POJ 2653 - Pick-up sticks 重拾计算几何..暴力得不忍直视...

                 题意:

                          现在按先后顺序放置N(N<=100000)个木棍(用线段表示)...问有多少个木棍是没有被压着的...

                 题解:

                          现在的风格简洁很多了..此题两个字..暴力


Program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<time.h>
#define ll long long
#define oo 1000000009
#define MAXN 100051
#define pi acos(-1.0)
#define eps 1e-5
using namespace std;    
struct Point
{
       double x,y;
};
struct Line
{
       Point p0,p1;
}L[MAXN]; 
int ans[MAXN];
double xMul(Point p0,Point p1,Point p2)
{
       double x1=p1.x-p0.x,y1=p1.y-p0.y,x2=p1.x-p2.x,y2=p1.y-p2.y;
       return x1*y2-x2*y1;
}
bool judge(Line h1,Line h2)
{ 
       if (xMul(h1.p0,h1.p1,h2.p0)*xMul(h1.p0,h1.p1,h2.p1)>=eps) return false;
       if (xMul(h2.p0,h2.p1,h1.p0)*xMul(h2.p0,h2.p1,h1.p1)>=eps) return false;
       return true;
}
int main()
{        
       int n,i,j,num; 
       while (~scanf("%d",&n) && n)
       {
                for (i=1;i<=n;i++)  
                   scanf("%lf%lf%lf%lf",&L[i].p0.x,&L[i].p0.y,&L[i].p1.x,&L[i].p1.y); 
                num=0;
                for (i=n;i>=1;i--)
                {
                       for (j=i+1;j<=n;j++)
                          if (judge(L[i],L[j]))
                             break;
                       if (j>n) ans[++num]=i;
                }
                printf("Top sticks:");
                for (i=num;i>1;i--) printf(" %d,",ans[i]);
                printf(" %d.\n",ans[1]);
       }
       return 0;
}


你可能感兴趣的:(POJ 2653 - Pick-up sticks 重拾计算几何..暴力得不忍直视...)