| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么才能不超时阿 我的代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator