P2665 [USACO08FEB]连线游戏Game of Lines
不平行就是直线斜率不同
枚举所有两点的斜率,对平行坐标轴的线特殊考虑
离散化一下就好了
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=4e4+7; const double INF=2e9+7; int n,pos[207][2],cnt,ans; double k[N]; int main() { n=read(); for(int i=1;i<=n;i++) pos[i][0]=read(),pos[i][1]=read(); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { cnt++; if(pos[i][0]==pos[j][0]) { k[cnt]=INF; continue; } if(pos[i][1]==pos[j][1]) { k[cnt]=0; continue; } k[cnt]=(double)(pos[i][1]-pos[j][1])/(double)(pos[i][0]-pos[j][0]); } sort(k+1,k+cnt+1); ans=1; for(int i=2;i<=cnt;i++) if(k[i]!=k[i-1]) ans++; printf("%d",ans); return 0; }