poj 3304

搞了一星期竞赛。。。题没写。。作业也没写qaq

这个判断是否存在直线使各线段投影都直线上有公共部分。。。假设直线存在,那么在这个公共部分作该直线的垂线必然会与各线段相交,还可以对该直线进行旋转和平移,临界状态是经过2个线段的端点,那么我们可以枚举这2个端点,看经过这2个端点的直线是否与所有线段相交。。

当然要注意只有一个线段的情况,还有注意精度问题(题目视坐标差小于eps的点为重合点)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inf 1e9
#define eps 1e-8
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&&(-x))
#define NM 1000
using namespace std;

int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f*x;
}





struct P{
	double x,y;
	P(double x=0,double y=0):x(x),y(y){}
	P operator-(const P&o){return P(x-o.x,y-o.y);}
	double operator*(const P&o){return x*o.y-y*o.x;}
}a[NM],b[NM],c[NM];
int n;
int main(){
	//freopen("data.in","r",stdin);
	int T=read();
	while(T--){
		n=read();
		mem(a);mem(b);mem(c);
		inc(i,1,n)scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&b[i].x,&b[i].y);
		inc(i,1,n)c[i*2]=a[i],c[i*2+1]=b[i];
		inc(i,2,n*2+1)inc(j,i+1,n*2+1)
		if(abs(c[i].x-c[j].x)>eps||abs(c[i].y-c[j].y)>eps){
			P p=c[i]-c[j];bool f=true;
			inc(k,1,n)
				if((p*(a[k]-c[i]))*(p*(b[k]-c[i]))>eps)f=false;
			if(f){puts("Yes!");
				//printf("%d %d\n",i,j);
				goto la;}
		}
		puts("No!");
la:;
	}
	return 0;
}


Segments
Time Limit: 1000MS		Memory Limit: 65536K
Total Submissions: 15937		Accepted: 5052

Description

Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.

Input

Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.

Output

For each test case, your program must output "Yes!", if a line with desired property exists and must output "No!" otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.

Sample Input

3
2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3
0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3
0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0

Sample Output

Yes!
Yes!
No!

Source
Amirkabir University of Technology Local Contest 2006

[Submit]   [Go Back]   [Status]   [Discuss] 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值