bzoj1610 / P2665 [USACO08FEB]连线游戏Game of Lines
P2665 [USACO08FEB]连线游戏Game of Lines
第一次写快读没判负数....(捂脸)
暴力$O(n^2)$求斜率,排序判重。
注意垂直方向的直线要特判。
end.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cctype> 6 #define re register 7 using namespace std; 8 typedef double db; 9 void read(int &x){ 10 char c=getchar();x=0; bool f=1; 11 while(!isdigit(c)) f=(f&&c!='-'),c=getchar(); 12 while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar(); 13 x=f?x:-x; 14 } 15 #define N 202 16 const db eps=1e-8; 17 struct node{int x,y;}a[N]; 18 int n,tp,ans=1; db k[N*N]; 19 int main(){ 20 read(n); 21 for(re int i=1;i<=n;++i){ 22 read(a[i].x);read(a[i].y); 23 for(re int j=1;j<i;++j){ 24 db r1=a[i].y-a[j].y; 25 db r2=a[i].x-a[j].x; 26 if(r2<eps&&r2>-eps) k[++tp]=100000;//特判 27 else k[++tp]=r1/r2; 28 } 29 }sort(k+1,k+tp+1); 30 for(re int i=2;i<=tp;++i) 31 if(k[i]>k[i-1]) ++ans;//判重 32 printf("%d",ans); 33 return 0; 34 }