POJ2653Pick-up sticks

枚举每根STICKS后面放的于其是否有焦点.

还有种VECTOR的写法,没搞出来....

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const double INF = 1e-8;
int dcmp(double t){
    if(fabs(t) < INF) return 0;
    if(t < 0)   return -1;
    return 1;
}
struct point{
    double x ,y;
point (double a = 0,double b = 0){
    x = a;y = b;
}
};
typedef point Vector;
point operator - (const point &a,const point &b){
    return point(a.x - b.x , a.y - b.y);
}
double cross(point &p,point &l1,point &l2){
    return ((l1.x - p.x)*(l2.y - p.y) - (l1.y - p.y)*(l2.x - p.x));
}
double cross(Vector a,Vector b){
    return a.x * b.y - a.y * b.x;
}
struct segment{
    point s,e;
    int number;
    segment(point a,point b,int n){s = a; e = b;number = n;}
    segment(){
    s = point(0,0);e = point(0,0);number = 0;}
};
segment p[1001000];

bool SegmentItersection(point a1, point a2, point b1, point b2)
{
    double c1 = cross(a2-a1, b1-a1), c2 = cross(a2-a1, b2-a1),
    c3 = cross(b2-b1, a1-b1), c4 = cross(b2-b1, a2-b1);
    return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;
}

int pcount = 0;
int n;
bool flag [1000010];
int main()
{
    int n , topsize;
    double x1,x2,y1,y2;
    segment temp(point(0,0),point(0,0),0);
    int temp1;
    while(1){
            scanf("%d",&n);
                if(n ==0  ) return 0;
            memset(flag,0,sizeof(flag));
            for(int i = 0 ;i < n; i++)
            scanf("%lf%lf%lf%lf",&p[i].s.x,&p[i].s.y,&p[i].e.x,&p[i].e.y);
            for(int i = 0 ;i < n ;i++)
                    for(int j = i + 1 ; j < n; j++)
                        if(SegmentItersection(p[i].e,p[i].s,p[j].e,p[j].s))
            {
                flag [i] =true;
                break;
            }
            printf("Top sticks: ");
        for(int i = 0; i < n; i++)
            if(flag[i]==0)
            {
                if(i==n-1)
                    printf("%d.\n",i+1);
                else
                    printf("%d, ",i+1);
            }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值