POJ 3304 Segments --枚举,几何】的更多相关文章

题意: 给n条线段,问有没有一条直线,是每条线段到这条直线上的投影有一个公共点. 解法: 有公共点说明有一条这条直线的垂线过所有线段,要找一条直线过所有线段,等价于从所有线段中任选两端点形成的直线存在可以穿过所有的线段的直线(可将A平移至一条线段端点,然后绕这点旋转,使A过另一条线段端点),然后O(n^2)的枚举找任意两个线段的两个端点,还要找自己这条线段的两个端点,形成一条直线 代码: #include <iostream> #include <cstdio> #include…
POJ 3304  Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以在那里作一条线,那么这条线就和所有线段都至少有一个交点,所以如果有一条直线和所有线段都有交点的话,那么就一定有解. 怎么确定有没直线和所有线段都相交?怎么枚举这样的直线?思路就是固定两个点,这两个点在所有线段上任意取就可以,然后以这两个点作为直线,去判断其他线段即可.为什么呢?因为如果有直线和所有线段都相…
题目传送门:POJ 3304 Segments 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. Inp…
POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes.可是注意去重. struct Point { double x, y; } P[210]; struct Line { Point a, b; } L[110]; double xmult(Point p1, Point p2, Point p) { return (p1.x-p.x)*(p2.y…
题目链接:POJ 3304 Problem 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…
LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断相交先求叉积再用跨立实验.枚举每个线段的起始结束点作为直线起点终点遍历即可. /** @Date : 2017-07-12 14:35:44 * @FileName: POJ 3304 基础线段交判断.cpp * @Platform: Windows * @Author : Lweleth (Sou…
题目传送门 题意:有若干线段,问是否存在一条直线,所有线段投影到直线上时至少有一个公共点 分析:有一个很好的解题报告:二维平面上线段与直线位置关系的判定.首先原问题可以转换为是否存在一条直线与所有线段相交,然后可以离散化枚举通过枚举端点来枚举直线,再用叉积判断直线和线段是否相交.用到了叉积 /************************************************ * Author :Running_Time * Created Time :2015/10/23 星期五…
//枚举过每一条线段的直线, //再判断其他线段的点在直线上或被直线穿过 //即求直线与线段相交(叉积) #include<stdio.h> #include<math.h> #define esp 1e-8 struct Node { double x,y; } a[],b[],c[],tmp1,tmp2; double cal(Node a,Node b,Node c)//ca*cb { return ((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.…
Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 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…
Segments 题意:给你100以内的n条线段,问你是否存在一条直线,使得题给的线段在这条直线上的“投影” 相交于一点: 思路: 1.先要将线段投影相交于一点转变为存在一条直线与所有的线段相交: 很自然的想到,当存在一条直线使得所有的线段的投影都相交于一点时,过这点与该直线垂直的直线必定与所有的直线相交: 2.如何判断这样的直线是否存在呢? 假设这样的直线存在,则这条直线的所能转动的极限位置就是与题目所给的线段的端点重合,这就直接枚举任意两条线段的两个端点:还有就是怎么知道所枚举出来的直线就与…
  Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11593   Accepted: 3657 Description Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segmen…
Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 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…
Segments Time Limit: 1000MS Memory Limit: 65536K 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…
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 n…
题意:有n条线段,问有没有一条直线使得所有线段在这条直线上的投影至少有一个共同点. 思路:逆向思维,很明显这个问题可以转化为是否有一条直线穿过所有线段,若有,问题要求的直线与该直线垂直,并且公共点为垂足. 因此只需要枚举每两个端点形成的直线,判断是否和所有线段相交.证明,若存在一条与所有线段相交的直线L,则可以将L平移直到再移动就不满足"与所有线段相交"这个条件时,此时L经过某个线段的一个端点,再将L旋转直到再旋转就不满足“与所有线段相交"这个条件时,肯定与另一个端点相交.…
题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1的时候,如下图,线段AB在直线L上的投影为线段A'B',则过任意介于A'B'之间的点C'做直线L的垂线必交线段AB与一点C:反之,过线段AB之间任意一点C做直线L的垂线,垂足必定落在A'B'之间. 不难将此结论推广到n条线段的情况,假设存在一满足题意的直线L,则设点A为各个线段在L上投影的公共点,那…
题目: 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…
Segments Time Limit: 1000MS   Memory Limit: 65536K       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…
<题目链接> 题目大意: 给出一些线段,判断是存在直线,使得该直线能够经过所有的线段.. 解题思路: 如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,问题转化为问是否存在一条线和所有线段相交. 如果存在这么一条直线,那么该直线一定能够移成经过两个端点的形式.枚举所有线段的两个端点,判断该直线和所有线段是否相交即可. #include <iostream> #include <math.h> #include <cstdio> us…
原题 给出n条线段,判断是否有一条直线与所有线段都有交点 若存在这样一条直线,那么一定存在一条至少过两个线段的端点的直线满足条件. 每次枚举两条线段的两个端点,确定一条直线,判断是否与其他线段都有交点. 判断交点: 判断AB和CD是否相交,即判断AC×BD(叉积)和AD×BC(叉积)是否同号 #include<cstdio> #define eps 1e-13 #define N 110 using namespace std; int t,n; struct point { double x…
Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14178   Accepted: 4521 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…
Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10921   Accepted: 3422 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…
收获:举一反三:刷一道会一道 1:思路转化:(看的kuangbin的思路) 首先是在二维平面中:如果有很多线段能够映射到这个直线上并且至少重合于一点,充要条件: 是过这个点的此条直线的垂线与其他所有直线都相交 取极限情况: 此垂线与直线的交点是端点的情况 则可以通过枚举所有的端点所在的直线进行判断,若不存在这样的直线,则输出No! 细节:枚举的两端点存在重合的情况 为了谨慎起见:枚举所有可能情况,包括输入的线段所在的直线也是垂线的情况 2:直线与线段相交和线段与线段相交的区别: 线段的端点是不可…
题意: 找出一条直线,让给出的n条线段在这条直线的投影至少有一个重合的点 转化一下,以重合的点作垂线,那么这条直线一定经过那n条线段.现在就是求找到一条直线,让这条直线经过所有线段 分析: 假设存在这一条直线,我们以无穷远处作为支点,然后旋转,直到碰到一个线段的端点就停止旋转,此时还是穿过了所有线段: 然后以这个端点为支点,旋转直线,直到碰到一个线段的端点就停止旋转,此时也穿过了所有线段. 于是就证明了,如果直线与所有线段相交,那么必定存在一条直线经过线段中的两个端点 那么,接下来枚举即可.注意…
题目链接 题意 : 能否找出一条直线使得所有给定的线段在该直线上的投影有一个公共点. 思路 : 假设存在一条直线a使得所有线段在该直线上的投影有公共点,则必存在一条垂直于直线a的直线b,直线b与所有线段相交,所以问题又转变为是否存在一条直线与所在所有线段相交. 假设这样的直线存在,则这一条直线可能与某一条或者某些线段的端点重合,也可能不重合.对于那些没有在端点相交的线段,我们可以把这一条直线通过旋转或平移,让其先与一条线段在线段的端点相交(那此时这一条直线与别的线段就在别的线段的中间相交), 然…
意甲冠军:给出的一些段的.问:能否找到一条直线,通过所有的行 思维:假设一条直线的存在,所以必须有该过两点的线,然后列举两点,然后推断是否存在与所有的行的交点可以是 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; struct Point { double x, y; Point() {} Point(dou…
#include<cstdio> #include<algorithm> #include<cstring> #define N 105 #define eps 1e-8 using namespace std; double abs (double x) { return x>0?x:-x; } bool dcmp(double x,double y) { if (abs(x-y)<eps) return 1; return 0; } struct poi…
http://poj.org/problem?id=3304 Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9449   Accepted: 2902 Description Given n segments in the two dimensional space, write a program, which determines if there exists a line such that a…
// 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #includ…
The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1744 Description Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been…