POJ 2653 线段与线段相交 Pick-up sticks

题目链接:http://poj.org/problem?id=2653

分析:每输入一条线段,就将以前没有踢除的线段与之有交点的都踢除.最后留下的就是在最上面的.

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<vector>

using namespace std;
const int maxn=100000+100;

struct point{
    double x,y;
    void read(){
        scanf("%lf %lf",&x,&y);
    }
};
struct line{
    point st, en;
    int k;
    void read(int i){
        k=i; st.read(); en.read();
    }
}Rt;
double cross(point p0,point p1,point p2){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int work(line a,line b){
    double x = cross( a.st,a.en,b.st );
    double y = cross( a.st,a.en,b.en );
    if(x*y<=0)return 1;
    return 0;
}
bool del(line x){
    if( work(x,Rt)&&work(Rt,x) )return true;
    return false;
}
int main(){
    int n;
    while(cin>>n,n){
        vector<line>M;
        vector<line>::iterator it;
        for(int i=1;i<=n;++i){
            Rt.read(i);
            M.erase( remove_if(M.begin(),M.end(),del),M.end() );
            M.push_back(Rt);
        }
        printf("Top sticks:");
        for(it=M.begin();it!=M.end();++it){
            if(it+1==M.end())
                cout<<' '<<it->k<<'.'<<endl;
            else cout<<' '<<it->k<<',';
        }
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值