Segments
Segments
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 x1y1 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!
题目的意思是,求一条直线,将已知线段投影到这条直线上有一个共同交点,判断是否存在这条直线。
这题要直接去求会很麻烦。但是想一想,将所有线段投影后,如果有共同点,则,这个点实际上是由n个点叠在一起的。如果我们把它展开了,以另一个视角观察将会是这样的:

所有线段在直线ansL上都会有一个共同的投影点,A。再观察,发现那些投影到A点的点都被直线L所经过。所以,题目就变成了,判断是否存在一条直线,与所有线段相交。
在实际操作时,只需枚举2n个点中任意两个点,判断经过这两点的直线是否符合要求。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
;
int n;
],v[];
point operator - (point P,point Q){point ret; ret.x=P.x-Q.x,ret.y=P.y-Q.y; return ret;}
double cross(point P,point Q){return P.x*Q.y-Q.x*P.y;}
bool jug(point P,point Q){
;
; i<n; i++) ;
;
}
int main(){
int T;
for (scanf("%d",&T); T; T--){
scanf("%d",&n);
; i<n; i++) scanf("%lf%lf%lf%lf",&u[i].x,&u[i].y,&v[i].x,&v[i].y);
; ) flag=;
; i<n-; i++) if (!flag)
; j<n; j++) if (!flag)
if(jug(u[i],u[j])||jug(u[i],v[j])||jug(v[i],u[j])||jug(v[i],v[j])) flag=true;
printf("%s\n",flag?"Yes!":"No!");
}
;
}
Segments的更多相关文章
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor
结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...
- Application package 'AndroidManifest.xml' must have a minimum of 2 segments.
看了源码就是packagename里面必须包含一个. 源码在: ./sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/id ...
- segments&cache
Segments 执行效果 命令 在 sense 里边执行 GET /abcd/_segments 前边的是索引名称,后边是请求 段信息 说明 索引是面向分片的,是由于索引是由一个或多个分片( ...
- [UCSD白板题] Points and Segments
Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...
- [UCSD白板题] Covering Segments by Points
Problem Introduction You are given a set of segments on a line and your goal is to mark as few point ...
- MAPPING SEGMENTS TO PAGES
The segmentation and paging mechanisms provide in the support a wide variety of approaches to memory ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- Leetcode: Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- Codeforces Round #337 Vika and Segments
D. Vika and Segments time limit per test: 2 seconds memory limit per test: 256 megabytes input ...
随机推荐
- Selenium Webdriver 自动化测试开发常见问题(C#版)
转一篇文章,有修改,出处http://www.7dtest.com/site/blog-2880-203.html 1:Selenium中对浏览器的操作 首先生成一个Web对象 IWebDriver ...
- 【译】第44节---EF6-存储过程映射
原文:http://www.entityframeworktutorial.net/entityframework6/code-first-insert-update-delete-stored-pr ...
- Lintcode455-StudentID-Easy
Implement a class Class with the following attributes and methods: A public attribute students which ...
- Lintcode521-Remove Duplicate Numbers in Array-Easy
Description Given an array of integers, remove the duplicate numbers in it. You should: Do it in pla ...
- 理解 Redis(5) - 哈希值
哈希值存储示意图:首先, 我想先认真理解一下哈希值的数据结构:前面讲过, redis 存储的是键值对, 键永远都是可以打印的 ASCII 码, 值是字符串, 或者是以其他形式包裹的字符串. 上两节介绍 ...
- hdu 5676 ztr loves lucky numbers 打表+二分
ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- 《Linux命令行与shell脚本编程大全》读书笔记
第一章:初识Linux 1.linux可划分为四个部分:内核.GNU工具.图形化桌面环境.应用程序 2.内核主要负责:系统内存管理.软件程序管理.硬件设备管理.文件系统管理 3.内核的系统内存管理,有 ...
- 力扣(LeetCode) 852. 山脉数组的峰顶索引
我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得A[0] < A[1] < ... A[i-1] ...
- cocos2dx 3.x 集成protobuf
vs2013+cocos2dx 3.13.1 这篇博文是集成Lua版本的protobuf,集成C++版本的过程也可参考. 主要参考博文地址<cocos2dx 3.x C++搭建protobuf环 ...
- sublime Text如何取消两栏窗口?
在菜单栏里的 View->LayOut->Single,也可以用快捷键 Alt+Shift+1.如图所示.(亲测可用) &lt;img src="https:// ...