Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:一直看不出有什么错,但就是一直WA,算法n*n

Posted by frkstyc at 2006-03-27 12:16:44 on Problem 2780
In Reply To:一直看不出有什么错,但就是一直WA,算法n*n Posted by:dearboy at 2006-03-27 11:09:29
4
0 1
1 0
2 1
1 2
你的程序根本没有输出

> //帮帮忙吧,试了N多数据...
> #include <iostream>
> #include <cstdio>
> #include <vector>
> using namespace std;
> 
> int  n;
> 
> int visit[2022][2022];//存放斜率
> int ta[2022],tb[2022];//处理斜率为0和不存在的情况
> int p[1022][2];
> 
> int gcd(int a,int b)
> {
> 	return b?gcd(b,a%b):a;
> }
> 
> void run()
> {
> 	int i,j;
> 	int x,y,com;
> 	int best=0;
> 	for(i=0;i<n;i++)
> 		scanf("%d%d",&p[i][0],&p[i][1]);
> 	memset(visit,0,sizeof(visit));
> 	memset(ta,0,sizeof(ta));
> 	memset(tb,0,sizeof(tb));
> 	for(i=0;i<n;i++)
> 		for(j=i+1;j<n;j++)
> 		{
> 			if(i==j)
> 				continue;
> 			x = p[i][0]-p[j][0];
> 			y = p[i][1]-p[j][1];
> 			if(x==0)
> 			{
> 				ta[p[i][0]+10]++;
> 				if(ta[p[i][0]+10]>best)
> 					best=ta[p[i][0]+10];
> 				continue;
> 			}
> 			if(y==0)
> 			{
> 				tb[p[i][1]+10]++;
> 				if(tb[p[i][1]+10]>best)
> 					best=tb[p[i][1]+10];
> 				continue;
> 			}
> 			com = gcd(x,y);
> 			x/=com;y/=com;
> 			if(x<0)
> 				x=-x,y=-y;
> 			visit[x+1000][y+1000]++;
> 			if(visit[x+1000][y+1000]>best)
> 				best=visit[x+1000][y+1000];
> 		}
> 	for(i=2;i<1005;i++)
> 		if(i*(i-1)==2*best)
> 			cout<<i<<endl;
> }
> 
> 
> int main()
> {
> 	while( scanf("%d" , &n) != EOF )
> 		run();
> 
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator