标签:
题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍.....
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<math.h> using namespace std; const int MAXN = 1e5+7; const double EPS = 1e-8; struct point { double x, y; point(double x=0, double y=0):x(x),y(y){} point operator - (const point &t) const{ return point(x-t.x, y-t.y); } double operator * (const point &t) const{ double ans = x*t.y - y*t.x; if(ans > EPS)return 1; if(fabs(ans) < EPS)return 0; return -1; } }; struct segment { point A, B; segment(point A=0, point B=0):A(A), B(B){} }; bool Intersect(segment a, segment b) { return (a.A-a.B)*(b.A-a.B)+(a.A-a.B)*(b.B-a.B) == 0; } int used[MAXN], ans[MAXN]; segment seg[MAXN]; bool Find(int k, int N) { for(int i=k+1; i<=N; i++) { if(Intersect(seg[k], seg[i]) && Intersect(seg[i], seg[k])) return true; } return false; } int main() { int N; while(scanf("%d", &N) != EOF && N) { for(int i=1; i<=N; i++) { scanf("%lf%lf%lf%lf", &seg[i].A.x, &seg[i].A.y, &seg[i].B.x, &seg[i].B.y); used[i] = false; } int k=0; for(int i=1; i<=N; i++) { used[i] = Find(i, N); if(!used[i])ans[k++] = i; } printf("Top sticks: "); for(int i=0; i<k-1; i++) printf("%d, ", ans[i]); printf("%d.\n", ans[k-1]); } return 0; }
Pick-up sticks - POJ 2653 (线段相交)
标签:
原文地址:http://www.cnblogs.com/liuxin13/p/4790347.html