本文目录一览:
C语言大题目!!求解!!
实在改不出来了,改了几天找不着毛病,可以输出雷达数量和坐标,但是有重复,楼主你自己改改吧。成功了麻烦发消息把源程序给我。谢了!
#include stdio.h
#include math.h
#define D 3
double minlocation(double x[],double y[],int i,int number)
{ double location=x[i];
while(( (location-x[i])*(location-x[i]) + y[i]*y[i] )(D*D) locationx[number-1])
location+=0.001;
return location-0.001;
}
int selectmin(int flag[])
{ int i=0;
while(flag[i])
i++;
return i;
}
void mark(double x[],double y[],double r[],int *f,int ra,int number)
{ int island;
double length,m,n;
for(island=0;islandnumber;island++)
if(*(f+island)==0)
{ m=y[island]*y[island];
n=r[ra]-x[island];
length=m*m+n*n;
if(length=D*D)
*(f+island)=1;
printf("f[%d]=%d\n",island,*(f+island));
}
}
main()
{ double island_x[20],island_y[20],radar[20];
int flag[20]={0};
int number,*pflag;
int i,min,k=0,ff,m;
printf("input the number of islands:");
scanf("%d",number);
printf("input the location of islands:(x and y)");
for(i=0;inumber;i++)
scanf("%lf%lf",island_x[i],island_y[i]);
for(i=0;inumber;i++)
if(island_y[i]D)
{ printf("This project is impossible!\n");
goto loop;
}
for(i=0;inumberffnumber;i++)
{ ff=0;
min=selectmin(flag);
printf("now it's %d turn\n",min);
radar[k]=minlocation(island_x,island_y,min,number);
pflag=flag[0];
for(m=0;m=k;m++)
mark(island_x,island_y,radar,pflag,m,number);
for(m=0;mnumber;m++)
if(flag[m]==1)
ff++;
printf("the number of flag is %d\n",ff);
if(ffnumber)
k++;
}
printf("the number of radar is %d\n",k);
for(i=0;ik;i++)
printf("the %d radar is %-8.2lf\n",i+1,radar[i]);
loop:
;
}
C语言求小岛面积
#define N 20
void main() {
int n,i,j,k,b,a[N][N],s;
scanf("%d",n); if ( nN ) n=N;
for ( i=0;in;i++ ) for ( j=0;jn;j++ ) scanf("%d",a[i][j]);
for ( i=s=0;in;i++ )
for ( j=0;jn;j++ ) {
b=0; for ( k=0;ki;k++ ) if ( a[k][j] ) { b=1;break; } if ( !b ) continue;
b=0; for ( k=i+1;kn;k++ ) if ( a[k][j] ) { b=1;break; } if ( !b ) continue;
b=0; for ( k=0;kj;k++ ) if ( a[i][k] ) { b=1;break; } if ( !b ) continue;
b=0; for ( k=j+1;kn;k++ ) if ( a[i][k] ) { b=1;break; } if ( !b ) continue;
s++;
}
printf("%d\n",s);
}
c语言编程:最大岛屿问题 A国是个岛国,由若干个小岛组成。A国地图如下所示:
#include stdio.h
char map[100][100];
int n, m;
int total, maxArea, area;
void GetMap()
{
scanf("%d%d\n", n, m);
for (int i = 0; i n; ++i)
{
for (int j = 0; j m; ++j)
{
scanf("%c", map[i][j]);
}
getchar();
}
}
void Search(int x, int y)
{
if (x 0 || x = n || y 0 || y = m || map[x][y] == '.')
{
return;
}
++area;
map[x][y] = '.';
Search(x - 1, y - 1);
Search(x - 1, y);
Search(x - 1, y + 1);
Search(x, y - 1);
Search(x, y + 1);
Search(x + 1, y - 1);
Search(x + 1, y);
Search(x + 1, y + 1);
}
void GetResult()
{
for (int i = 0; i n; ++i)
{
for (int j = 0; j m; ++j)
{
if (map[i][j] == 'I')
{
++total;
area = 0;
Search(i, j);
if (maxArea area)
{
maxArea = area;
}
}
}
}
}
int main()
{
GetMap();
GetResult();
printf("%d %d\n", total, maxArea);
return 0;
}