为什么我的程序这组数据过不了?
题目是:
Description
Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) distinct lattice points. Dot i has the integer coordinates Xi and Yi (-1,000 ≤ Xi ≤ 1,000; -1,000 ≤ Yi ≤ 1,000).
Bessie can score a point in the game by picking two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has asked you to help find the maximum score she can obtain.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 describes lattice point i with two space-separated integers: Xi and Yi.
Output
* Line 1: A single integer representing the maximal number of lines Bessie can draw, no two of which are parallel.
Sample Input
4
-1 1
-2 0
0 0
1 1
Sample Output
4
我的程序是:
/* Note:Your choice is C IDE */
#include
#include
int main()
{
int n,k=1,y=0,flag=0,i,j,f,m=0;
float z[210][2],x[20000],flag2[220];
scanf("%d",&n);
memset(flag2,0,sizeof(flag2));
for(i=0;i<n;i++)
scanf("%f%f",&z[0],&z[1]);
for(i=0;i<n;i++)
{
if(flag2!=1)
{
for(j=i+1;j<n;j++)
{
if(flag2[j]!=1&&z[0]==z[j][0])
{flag2[j]=1;flag=1;}
}
if(flag==1)
{y++;flag=0;}
}
}//得到的y就是相同横坐标的组数
//测试时调用printf("%d ",y);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(z[0]!=z[j][0])
x[k++]=(z[j][1]-z[1])/(z[j][0]-z[0]);
}
}
f=k-1;//f为斜率的个数
//测试时调用 printf("%d ",f);
if(f==1){printf("1\n");return 0;}
for(i=1;i<=f;i++)
{
for(j=i+1;j<=f;j++)
{
if(fabs(x-x[j])<0.000000001)
break;
}
if(j==f+1)
m++;//m为不同斜率的个数
}
printf("%d\n",y+m);
return 0;
}
我测试过,这组数据
4
1 2
1 3
4 5
4 6
过不了,结果为5,正确的应该是6,哪里有问题啊??急寻大侠解决!!
我测试过,这组数据
4
1 2
1 3
4 5
4 6
过不了,结果为5,正确的应该是6,哪里有问题啊??急寻大侠解决!!
这里应该为
过不了,结果为5,正确的应该是4,哪里有问题啊??急寻大侠解决!!
确实,题目看漏了,平行四边形是4,我错了,
Sample里的数据却过得了,谢谢你的回答,让我发现我程序里思想有些前后不一!~~~
那怎么该该可以Accpet呢?
|