为什么我的程序这组数据过不了ACM

[复制链接]
查看11 | 回复1 | 2008-8-7 10:55:33 | 显示全部楼层 |阅读模式
为什么我的程序这组数据过不了?
题目是:
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呢?

回复

使用道具 举报

千问 | 2008-8-7 10:55:33 | 显示全部楼层
正确结果是6?你确定你这组测试数据没写错?这不还是个平行四边形么?还是4啊?那题目里这句话不白写了?however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line.Sample里的数据不就是个平行四边形么?难道我哪里理解错了?……呵呵~~加油~~早日解决~~这个实在抱歉,没大看懂你写的程序……我按我的思路写了一下,希望对你有帮助~~枚举出所有线段的斜率,特殊的斜率无穷大的另设标记,最后先对斜率排序,找出不重复的,再加上斜率无穷大的(如果有的话),
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行