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

怎么才能不超时阿 我的代码

Posted by xiaxia at 2006-03-26 22:27:55 on Problem 2780
#include <iostream>
using namespace std;

bool visit[1000][1000];
int xy[1000][2];
int n, ans, tans, dx,  dy;
int i, j, k, h;
int line[1000];
int len;
int main()
{
	while(scanf("%d", &n) == 1)
	{
	    memset(visit, false, sizeof(visit));
		for(i = 0; i < n; i ++)
		{
			scanf("%d %d", &xy[i][0], &xy[i][1]);
		}
		ans = 2;
		for(i = 0; i < n - ans; i ++)
			for(j = i + 1; j < n; j ++)
			{	
				if(!visit[i][j] && n - j + 1> ans)
				{
					tans = 2;
					dx = xy[i][0] - xy[j][0];
					dy = xy[i][1] - xy[j][1];
					len = 0;
			        line[len ++] = i;
					line[len ++] = j;
					for(k = j + 1; k < n; k ++)
						if((xy[k][0] - xy[i][0])*dy == (xy[k][1] - xy[i][1])*dx)
						{ 
							tans ++;
							line[len ++] = k;
						}     
					for(k = 0; k < len; k ++)
					  for(h = k + 1; h < len; h ++)
						visit[line[k]][line[h]] = true;
					ans = ans > tans ? ans : tans;
				}									
			}
			printf("%d\n", ans);
		
			
	}
    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