POJ 2653 Pick-up sticks

证明在这篇博客里https://blog.csdn.net/qq_43708222/article/details/99052341

#include<cstdio>
#include<cmath>

using namespace std;
const int N = 1e6 + 7;

double dx1[N];
double dx2[N];
double dy1[N];
double dy2[N];

double cal(double x1,double y1,double x2,double y2) {
	return (x1 * y2) - (x2 * y1);
}

bool isIntersect(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) {
	double x = x2 - x1;
	double y = y2 - y1;
	double cal1 = cal(x3 - x1,y3 - y1,x,y);
	double cal2 = cal(x4 - x1,y4 - y1,x,y);
	if(cal1 * cal2 > 0)	return false;
	x = x4 - x3;
	y = y4 - y3;
	cal1 = cal(x1 - x3,y1 - y3,x,y);
	cal2 = cal(x2 - x3,y2 - y3,x,y);
	if(cal1 * cal2 > 0)	return false;
	return true;
}


int main() {
	int n;
	while(~scanf("%d",&n) && n) {
		for(int i = 0; i < n; i++)
			scanf("%lf%lf%lf%lf", &dx1[i], &dy1[i], &dx2[i], &dy2[i]);
		bool flag;
		printf("Top sticks: ");
		for(int i = 0; i < n - 1; i++) {
			flag = 0;
			for(int j = i + 1; j < n; j++) {
				if(isIntersect(dx1[i],dy1[i],dx2[i],dy2[i],dx1[j],dy1[j],dx2[j],dy2[j])) {
					flag = 1;
					break;
				}
			} 
			if(!flag) {
				printf("%d, ",i + 1);
			}
		}
		printf("%d.\n",n);
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值