poj 2653 Pick-up sticks

本文深入探讨了数据比较中的暴力破解策略,并提供了一个高效算法的实现案例,通过使用C++编程语言,展示了如何在复杂的数据结构中进行精确且快速的比较操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据比较水,暴力破无压力。

CODE:

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

using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define oo 1e6
#define eps 1e-8
#define nMax 100000
#define pb push_back
#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)

int dcmp(double x){
    if(fabs(x)<eps) return 0;
    return x>0?1:-1;
}
struct point {
    double x,y;
    point(double x=0,double y=0): x(x),y(y) {}
    void make(double _x,double _y) {x=_x;y=_y;}
    void read(){ scanf("%lf%lf",&x,&y); }
    double len(){ return sqrt(x*x+y*y); }
    friend point operator -(point const& u,point const& v) {
        return point(u.x-v.x,u.y-v.y);
    }
    friend double operator *(point const& u,point const& v) {
        return u.x*v.y-u.y*v.x;
    }
    friend double operator ^(point const& u,point const& v) {
        return u.x*v.x+u.y*v.y;
    }
    friend point operator *(double const& k,point const& v) {
        return point(k*v.x,k*v.y);
    }
    friend point operator /(point const& u,double const& k){
        return point(u.x/k,u.y/k);
    }
    friend int dots_online(point,point,point);
};
int dots_online(point a,point b,point c){ return dcmp((a-c)*(b-c))==0; }
typedef struct line{
    point a,b;
    line() {}
    line(point a,point b): a(a),b(b) {}
    void make(point _a,point _b) {a=_a;b=_b;}
    void read() { a.read(),b.read(); }
    friend int intersection(line,line);
} segment;
int dot_in_line(point p,line l){
    return dcmp((l.a-p)*(p-l.b))==0 && dcmp((l.a-p)^(p-l.b))>=0;
}
int sameside(point a,point b,line l){
    return dcmp((l.a-a)*(a-l.b)) * dcmp((l.a-b)*(b-l.b)) > 0;
}
int intersection(line u,line v){
    if(dots_online(u.a,u.b,v.a) && dots_online(u.a,u.b,v.b))
        return dot_in_line(u.a,v) || dot_in_line(u.b,v) || dot_in_line(v.a,u) || dot_in_line(v.a,u);
    else
        return !sameside(u.a,u.b,v) && !sameside(v.a,v.b,u);
}

vector<int> ans;
line l[nMax];
void ins(int id){
    for(int i=0;i<ans.size();) if(intersection(l[ans[i]],l[id])) ans.erase(ans.begin()+i);else i++;
    ans.pb(id);
}
int n;
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    while(~scanf("%d",&n),n){
        ans.clear();
        for(int i=0;i<n;i++) {
            l[i].read();
            ins(i);
        }
        printf("Top sticks:");
        for(int i=0;i<ans.size();i++){
            printf(" %d",ans[i]+1);
            if(i==ans.size()-1) printf(".");
            else printf(",");
        }
        puts("") ;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值