LightOJ 1292 Laser Shot(暴力)

来源:互联网 发布:linux系统查看ip地址 编辑:程序博客网 时间:2024/06/01 12:50

题意:

让你选择一条线使这条线上的点最多。如果这题的n小一点的话,是可以n^3过的,但是他就是这么坑爹,700,所以只能n^2logn过。
我们只需要改变一下枚举的策略,对于每一个点p[i],我们算出所有其他点和这个点的斜率,然后统计一下哪种斜率最多就行了,用map存一下就好,顺便更新答案。
有一个坑点,就是如果点的个数小于三的话,答案就是n。

代码:

////  Created by  CQU_CST_WuErli//  Copyright (c) 2016 CQU_CST_WuErli. All rights reserved.//#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <set>#include <algorithm>#include <sstream>#define CLR(x) memset(x,0,sizeof(x))#define OFF(x) memset(x,-1,sizeof(x))#define MEM(x,a) memset((x),(a),sizeof(x))#define BUG cout << "I am here" << endl#define lookln(x) cout << #x << "=" << x << endl#define SI(a) scanf("%d",&a)#define SII(a,b) scanf("%d%d",&a,&b)#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)#define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1#define Root 1,n,1#define BigInteger bignconst int MAX_L=2005;// For BigIntegerconst int INF_INT=0x3f3f3f3f;const long long INF_LL=0x7fffffff;const int MOD=1e9+7;const double eps=1e-9;const double pi=acos(-1);typedef long long  ll;using namespace std;struct P{    int x,y;    P(){}    P(int x,int y):x(x),y(y){}};P p[710];int n;int main(int argc, char const *argv[]) {#ifdef LOCAL    freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);    // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);#endif    for (int T_T,kase=SI(T_T);kase<=T_T;kase++) {        SI(n);        rep(i,1,n) {            int x,y;            SII(p[i].x,p[i].y);        }        int ans=0;        map<pair<int,int>,int> mp;        rep(i,1,n)  {            mp.clear();            int cnt=0;            rep(j,1,n) if (i!=j) {                int dx=p[i].x-p[j].x;                int dy=p[i].y-p[j].y;                if (dx==0) {                    mp[make_pair(-1,-1)]++;                    cnt=max(cnt,mp[make_pair(-1,-1)]);                }                else {                    int tt=__gcd(dx,dy);                    dx/=tt;dy/=tt;                    mp[make_pair(dx,dy)]++;                    cnt=max(cnt,mp[make_pair(dx,dy)]);                }            }            ans=max(cnt,ans);        }        printf("Case %d: %d\n",kase,n<3?n:ans+1);    }    return 0;}
0 0