POJ_2653_Pick-up sticks_判断线段相交
POJ_2653_Pick-up sticks_判断线段相交
Description
Input
Output
The picture to the right below illustrates the first case from input. 
Sample Input
5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0
Sample Output
Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.
斯坦有各种长度的n条。他在地板上随意地扔了一个。在完成投掷后,斯坦试图找到最上面的棍子,那就是这些棍子,这样就没有棍子在上面了。
斯坦注意到,最后一根投掷棒总是在上面,但他想知道上面所有的棍子。斯坦棒非常非常薄,以至于它们的厚度可以被忽略。 暴力可过的一道题。直接枚举所有的所有的线段判断能不能被后面的覆盖即可。
然后判断线段相交用四次叉积判断即可。 代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef double f2;
#define N 100050
#define eps 1e-6
bool vis[N];
int ans[N],n;
struct Point {
f2 x,y;
Point() {}
Point(f2 x_,f2 y_) :
x(x_),y(y_) {}
Point operator + (const Point &p) const {return Point(x+p.x,y+p.y);}
Point operator - (const Point &p) const {return Point(x-p.x,y-p.y);}
Point operator * (f2 rate) const {return Point(x*rate,y*rate);}
};
f2 dot(const Point &p1,const Point &p2) {return p1.x*p2.x+p1.y*p2.y;}
f2 cross(const Point &p1,const Point &p2) {return p1.x*p2.y-p1.y*p2.x;}
f2 FABS(f2 x) {return x>0?x:-x;}
struct Line {
Point p,v;
Line() {}
Line(const Point &p_,const Point &v_) :
p(p_),v(v_) {}
};
Line a[N];
f2 turn(const Point &p1,const Point &p2,const Point &p3) {
return cross(p3-p1,p2-p1);
}
bool judge(const Line &l1,const Line &l2) {
if(turn(l1.p,l1.v,l2.p)*turn(l1.p,l1.v,l2.v)>0) return 0;
if(turn(l2.p,l2.v,l1.p)*turn(l2.p,l2.v,l1.v)>0) return 0;
return 1;
}
void init() {
memset(vis,0,sizeof(vis)); ans[0]=0;
}
void solve() {
init();
int i,j;
f2 x,y,z,w;
int fir=0;
for(i=1;i<=n;i++) {
scanf("%lf%lf%lf%lf",&a[i].p.x,&a[i].p.y,&a[i].v.x,&a[i].v.y);
}
printf("Top sticks:");
for(i=1;i<=n;i++) {
int flg=0;
for(j=i+1;j<=n;j++) {
if(judge(a[i],a[j])) {
flg=1; break;
}
}
if(!flg) {
if(!fir) {
fir=1;
}else printf(",");
printf(" %d",i);
}
}
puts(".");
}
int main() {
while(scanf("%d",&n)&&n) {
solve();
}
}
POJ_2653_Pick-up sticks_判断线段相交的更多相关文章
- 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)
传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(s ...
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- POJ 2653 Pick-up sticks(判断线段相交)
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7699 Accepted: 2843 De ...
- 判断线段相交(hdu1558 Segment set 线段相交+并查集)
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...
- hdu 1086(判断线段相交)
传送门:You can Solve a Geometry Problem too 题意:给n条线段,判断相交的点数. 分析:判断线段相交模板题,快速排斥实验原理就是每条线段代表的向量和该线段的一个端点 ...
- POJ_1066_Treasure Hunt_判断线段相交
POJ_1066_Treasure Hunt_判断线段相交 Description Archeologists from the Antiquities and Curios Museum (ACM) ...
- POJ_1556_The Doors_判断线段相交+最短路
POJ_1556_The Doors_判断线段相交+最短路 Description You are to find the length of the shortest path through a ...
- POJ 1066--Treasure Hunt(判断线段相交)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7857 Accepted: 3247 Des ...
- POJ2653 Pick-up sticks 判断线段相交
POJ2653 判断线段相交的方法 先判断直线是否相交 再判断点是否在线段上 复杂度是常数的 题目保证最后答案小于1000 故从后往前尝试用后面的线段 "压"前面的线段 排除不可能 ...
随机推荐
- javaScript(1)---概述
javaScript(1)---概述 学习要点: 1.什么是JavaScript 2.JavaScript特点 3.JavaScript历史 4.JavaScript核心 JavaScript诞生于1 ...
- [转]web服务器压力测试工具
http_load学习心得: 测试网站每秒所能承受的平均访问量(吞吐量) http_load -parallel 5 -fetches 1000 urls.txt这段命令行是同时使用5个进程,随机访问 ...
- 入职第二天:使用koa搭建node server是种怎样的体验
今天是我入职第二天,leader跟我说,昨天配置好了服务端渲染的文件,今天就先研究研究如何使用koa来搭建一个node server吧! 按照惯例,我去koa官网查了一下什么是koa,结果官网很简单的 ...
- java 操作Excel表格
对于Excel表格的解析.生成,java在 org.apache.poi 包中已经封装好了,使用比较简单. 解析Excel: 首先将File文件转成InputStream InputStream in ...
- jquery touch 移动端上下滑动加载
var touchStart, touchEnd, touchDiff = 80; $(window).on({ 'touchstart': function (e) { touchStart = e ...
- 利用分支限界法求解单源最短路(Dijkstra)问题
分支限界法定义:采用Best fist search算法,并使用剪枝函数的算法称为分支界限法. 分支限界法解释:按Best first的原则,有选择的在其child中进行扩展,从而舍弃不含有最优解的分 ...
- 获取linux帮助命令
命令的分类 linux的命令分为内部命令和外部命令. 内部命令指的是shell程序自带的命令,是shell程序的一部分,这些命令由shell程序识别并在shell程序内部完成运行,通常在linux系 ...
- 关于overfit的随笔
看到@ 爱可可-爱生活转发的文章.稍微看了下,在这里记录下. overfit是机器学习的一个重要概念.在狭义上可以定义为模型过于复杂,导致模型的generalization不够好.我认为应采用一个更广 ...
- 第六章之S5PV210正确启动u-boot
1,根据上一章最后一步生成u-boot写入到板子上,生成如下代码 UARU 0x43110220 DDR IS OK! 0x12345678 0xEA000014 U-Boot - ::) CPU: ...
- SpringMVC中Json数据格式转换
1 @RequestBody 作用: @RequestBody注解用于读取http请求的内容(字符串),通过springmvc提供的HttpMessageConverter接口将读到的内容转换为 ...