https://www.luogu.org/problemnew/show/P1142
枚举一个基点,枚举另一个点找出斜率,约分后存入。记得要加上那个点本身。
__gcd(x,y),返回值符号与y的符号相同。当x,y其中一个是0的时候,返回值是另一个。
所以根本不用特判直接除以g!
#include<bits/stdc++.h> using namespace std; #define ll long long int n; ll x[705],y[705]; map<pair<ll,ll> ,ll>m; void reduction(ll &y,ll &x){ //if(x==0) //y=1; //if(y==0) //x=1; ll g=__gcd(y,x); y/=g; x/=g; /*if(x<0){ y=-y; x=-x; }*/ //cout<<g<<endl; } int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld%lld",&x[i],&y[i]); } ll maxnum=0; for(int i=0;i<n;i++){ m.clear(); for(int j=0;j<n;j++){ if(j==i) continue; else{ ll dy=y[j]-y[i]; ll dx=x[j]-x[i]; reduction(dy,dx); m[{dy,dx}]++; } } ll tmax=0; for(auto i:m){ tmax=max(tmax,i.second); } maxnum=max(maxnum,tmax+1); } printf("%lld\n",maxnum); //cout<<__gcd(0,2)<<endl; //cout<<__gcd(1,0)<<endl; }
原文:https://www.cnblogs.com/Yinku/p/10336344.html