标签:sse names close struct size tps class nsis number
Pick-up sticks
Input
Output
Sample Input
5 1 1 4 2 2 3 3 1 1 -2.0 8 4 1 4 8 2 3 3 6 -2.0 3 0 0 1 1 1 0 2 1 2 0 3 1 0
Sample Output
Top sticks: 2, 4, 5. Top sticks: 1, 2, 3.
Hint
题目大意,先后给出n条直线,求最后哪些直线上没有直线.
那么,由于n最大100000,所有肯定不能用普通的来.
其实,我们只要记录最上面的几条直线就行了,并且可以用动态数组来.毕竟只有100000条直线,却有可能有n个集合,也有可能只有1个,所有,用vector代替普通的数组是再好不过的了.
然而,数据实在太强,还是TLE了.然而...暴力加break优化却AC了!!!
1 #include<cmath> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<vector> 6 #define Vec point 7 using namespace std; 8 const double eps=1e-8; 9 vector <int> que; 10 int n; 11 bool f[100005]; 12 struct point{ 13 double x,y; 14 void read(){scanf("%lf%lf",&x,&y);} 15 }seg[100005][2]; 16 int fabso(double x){return x<-eps?-1:x>eps;} 17 Vec operator + (point u,Vec v){ 18 Vec ret; ret.x=u.x+v.x,ret.y=u.y+v.y; 19 return ret; 20 } 21 Vec operator - (point u,point v){ 22 Vec ret; ret.x=u.x-v.x,ret.y=u.y-v.y; 23 return ret; 24 } 25 Vec operator * (Vec u,double v){ 26 Vec ret; ret.x=u.x*v,ret.y=u.y*v; 27 return ret; 28 } 29 Vec operator / (Vec u,double v){ 30 Vec ret; ret.x=u.x/v,ret.y=u.y/v; 31 return ret; 32 } 33 double cross(Vec u,Vec v){return u.x*v.y-u.y*v.x;} 34 bool dotonseg(point P,point U,point V){ 35 if ((P.x-U.x)*(P.x-V.x)>0) return 0; 36 if ((P.y-U.y)*(P.y-V.y)>0) return 0; 37 return cross(P-U,V-U)==0; 38 } 39 bool intersect(point P,point Q,point U,point V){ 40 if (fabso(cross(P-U,V-U)*cross(Q-U,V-U))<0&&fabso(cross(U-P,Q-P)*cross(V-P,Q-P))<0) return 1; 41 bool g1=dotonseg(P,U,V); 42 bool g2=dotonseg(Q,U,V); 43 bool g3=dotonseg(U,P,Q); 44 bool g4=dotonseg(V,P,Q); 45 if (g1||g2||g3||g4) return 1; 46 return 0; 47 } 48 int main(){ 49 for (scanf("%d",&n); n; scanf("%d",&n)){ 50 memset(f,1,sizeof f); 51 for (int i=1; i<=n; i++) seg[i][0].read(),seg[i][1].read(); 52 for (int i=1; i<=n-1; i++) 53 for (int j=i+1; j<=n; j++) 54 if (intersect(seg[i][0],seg[i][1],seg[j][0],seg[j][1])){f[i]=0; break;} 55 printf("Top sticks:"); 56 for (int i=1; i<n; i++) if (f[i]) printf(" %d,",i); 57 printf(" %d.\n",n); 58 } 59 return 0; 60 }
标签:sse names close struct size tps class nsis number
原文地址:http://www.cnblogs.com/whc200305/p/7183835.html