题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍.....

 
分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列,不过速度并不快,枚举才是最快的......据说是任意时刻没有超过1000个top sticks.....很难注意到。
 
代码如下:
=====================================================================================================================================
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std; const int MAXN = 1e5+;
const double EPS = 1e-; struct point
{
double x, y;
point(double x=, double y=):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 ;
if(fabs(ans) < EPS)return ;
return -;
}
};
struct segment
{
point A, B;
segment(point A=, point B=):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) == ;
} int used[MAXN], ans[MAXN];
segment seg[MAXN]; bool Find(int k, int N)
{
for(int i=k+; 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=; 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=; for(int i=; i<=N; i++)
{
used[i] = Find(i, N);
if(!used[i])ans[k++] = i;
} printf("Top sticks: ");
for(int i=; i<k-; i++)
printf("%d, ", ans[i]);
printf("%d.\n", ans[k-]);
} return ;
}
05-04 02:52