poj 3304
来源:互联网 发布:163 pop 端口 编辑:程序博客网 时间:2024/05/29 14:49
搞了一星期竞赛。。。题没写。。作业也没写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 1000using 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;}
SegmentsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 15937Accepted: 5052DescriptionGiven 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.InputInput 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.OutputFor 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 Input321.0 2.0 3.0 4.04.0 5.0 6.0 7.030.0 0.0 0.0 1.00.0 1.0 0.0 2.01.0 1.0 2.0 1.030.0 0.0 0.0 1.00.0 2.0 0.0 3.01.0 1.0 2.0 1.0Sample OutputYes!Yes!No!SourceAmirkabir University of Technology Local Contest 2006[Submit] [Go Back] [Status] [Discuss]
阅读全文
0 0
- POJ 3304
- poj 3304
- poj 3304
- poj 3304
- poj 3304
- POJ-3304
- poj 3304
- poj 3304
- poj 3304
- POJ 3304
- poj 3304
- POJ 3304 Segments
- POJ 3304 计算几何
- poj 3304 Segments
- poj 3304 Segments
- poj 3304 Segments
- POJ 3304 Segments
- poj 3304解题报告
- spring ioc原理(看完后大家可以自己写一个spring)
- android_listview_divider
- 理解伯德图- 1/4为什么要使用伯德图
- springboot集成验证码功能
- JAVA 类 : Person
- poj 3304
- http 请求数据返回 json 中中文字符为 unicode 编码转汉字转码
- Android图表库MPAndroidChart(十二)——来点不一样的,正负堆叠条形图
- 关于使用layer弹层插件获取其返回值
- iOS 原生sqlite3的使用
- RDM裸设备映射测试备忘
- SpringBoot整合Mybaties分页插件PageHelper
- Linux dd 命令
- idea spring托管hibernate并生成hibernate 实体类映射