Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 7550 | Accepted: 2789 |
Description
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
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> //Accepted 4116K 641MS C++ 1841B 2013-05-22 16:46:02 using namespace std; const int maxn = 100010; struct Point { double x; double y; }; struct V { bool mark; Point st; ///start; Point et; ///end V() { mark = true; } }; V v[maxn]; int n; double det(Point p1, Point p2, Point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x); } int Across(struct V v1, struct V v2) { if(max(v1.st.x, v1.et.x)>= min(v2.st.x, v2.et.x) && max(v2.st.x, v2.et.x)>= min(v1.st.x, v1.et.x) && max(v1.st.y, v1.et.y)>= min(v2.st.y, v2.et.y) && max(v2.st.y, v2.et.y)>= min(v1.st.y, v1.et.y) && det(v2.st, v1.et, v1.st)*det(v1.et, v2.et, v1.st)>=0 && det(v1.st, v2.et, v2.st)*det(v2.et, v1.et, v2.st)>=0 ) return 1; return 0; } void work() { for(int i = 1; i <= n-1; i++) { for(int j = i+1; j <= n; j++) { if(Across(v[i], v[j])) { v[i].mark = false; break; } } } vector<int> tmp; tmp.clear(); for(int i = 1; i <= n; i++) { if(v[i].mark) { tmp.push_back(i); } } printf("Top sticks: "); int maxsize = tmp.size(); for(int i = 0; i < maxsize-1; i++) { printf("%d, ", tmp[i]); } printf("%d.\n", tmp[maxsize-1]); } void init() { for(int i = 1; i <= n; i++) { v[i].mark = true; } } int main() { while(scanf("%d", &n) != EOF) { if(n==0) break; init(); for(int i = 1; i <= n; i++) { scanf("%lf%lf%lf%lf", &v[i].st.x, &v[i].st.y, &v[i].et.x, &v[i].et.y); } work(); } return 0; }