洛谷 - P1142 - 轰炸 - 计算几何
生活随笔
收集整理的這篇文章主要介紹了
洛谷 - P1142 - 轰炸 - 计算几何
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 longint 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
總結
以上是生活随笔為你收集整理的洛谷 - P1142 - 轰炸 - 计算几何的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 外卖(food) 洛谷4040宅男计划
- 下一篇: JavaWeb-SpringBoot_一