博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3304 Segments
阅读量:6199 次
发布时间:2019-06-21

本文共 2139 字,大约阅读时间需要 7 分钟。

Segments
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7363   Accepted: 2207

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

321.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.0

Sample Output

Yes!Yes!No!

Source

 
 
 
 
#include
#include
const int eps=1e-8;struct point{ double x,y;}p[410];double xmult(point a,point b,point c){ return (a.x-b.x)*(c.y-b.y)-(c.x-b.x)*(a.y-b.y);}double abs(double a){ if(a<0) return -a; return a;}bool work(int n){ int flag; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){ if(abs(p[j].x-p[i].x)>eps || abs(p[j].y-p[i].y)>eps){ flag=1; for(int k=1;k<=n;k+=2) if(xmult(p[i],p[j],p[k])*xmult(p[i],p[j],p[k+1])>0){ flag=0; break; } if(flag) return 1; } } return 0;}int main(){ //freopen("input.txt","r",stdin); int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); int cnt=1; for(int i=1;i<=n;i++,cnt+=2) scanf("%lf%lf%lf%lf",&p[cnt].x,&p[cnt].y,&p[cnt+1].x,&p[cnt+1].y); if(work(cnt-1)) printf("Yes!\n"); else printf("No!\n"); } return 0;}

 

转载地址:http://pptca.baihongyu.com/

你可能感兴趣的文章
python多线程与threading模块
查看>>
python一等函数
查看>>
js页面字段的必填验证方法
查看>>
idea+springboot+freemarker热部署
查看>>
linux 文件查阅 cat、more、less、tail
查看>>
Cflow使用详解【转】
查看>>
一次触摸屏中断调试引发的深入探究【原创】
查看>>
条款49:了解new-handle行为
查看>>
无法启动T-SQL调试。未能连接到计算机"."。这是在主机名解析时通常出现的暂时错误……...
查看>>
DevExpress GridControl 单元格添加进度条(ProgressBar)
查看>>
.NET动态调用WebService
查看>>
intelliJ IDEA 中快速定位当前文件路径
查看>>
do not kown
查看>>
(转)详解Javascript 中的this指针
查看>>
2017 多校1 I Curse Myself
查看>>
***文件上传控件bootstrap-fileinput的使用和参数配置说明
查看>>
2016国产开源软件TOP100(Q1)
查看>>
二叉搜索树的最近公共祖先的golang实现
查看>>
【ArcGIS】文件地理数据库,个人地理数据库与ArcSDE的局别
查看>>
电子商务网站必须具备的六大功能
查看>>