uva270 - Lining Up

题意不难,思路不难,

就是题目中一句话把我整蒙了,>>"Your program has to be efficient!"

我以为简单的暴力解决不了这个问题,所以我苦思冥想,,,,,却无果

不管是什么样的算法都是遍历,看了人家的code。恍然大悟,这题又是一只纸老虎,原以为要卡时间呢。

代码如下:

#include <cstdio>
const int M = 700+10;
char t[100];
int x[M], y[M], n;
void solve()
{
    int max = 0;
    for(int i = 0; i < n; i++)  for(int j = i+1; j < n; j++)
    {
        int num = 0;
        for(int k = j+1; k < n; k++)
            if((x[i]-x[j])*(y[j]-y[k])==(y[i]-y[j])*(x[j]-x[k])) num++;
        if(max<num) max = num;
    }
    printf("%d\n",max+2);
}
int main ()
{
    int cas;
    scanf("%d",&cas);getchar(); getchar();
    while(cas--)
    {
        n = 0;
        while(gets(t)&&t[0]!=0) { sscanf(t,"%d%d",&x[n],&y[n]); n++;}
        solve();
        if(cas)printf("\n");
    }
    return 0;
}


你可能感兴趣的:(uva270 - Lining Up)