hdu 1147(线段相交)
Pick-up sticks
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2673 Accepted Submission(s): 975
has n sticks of various length. He throws them one at a time on the
floor in a random way. After finishing throwing, Stan tries to find the
top sticks, that is these sticks such that there is no stick on top of
them. Stan has noticed that the last thrown stick is always on top but
he wants to know all the sticks that are on top. Stan sticks are very,
very thin such that their thickness can be neglected.
consists of a number of cases. The data for each case start with 1 ≤ n ≤
100000, the number of sticks for this case. The following n lines
contain four numbers each, these numbers are the planar coordinates of
the endpoints of one stick. The sticks are listed in the order in which
Stan has thrown them. You may assume that there are no more than 1000
top sticks. The input is ended by the case with n=0. This case should
not be processed.
each input case, print one line of output listing the top sticks in the
format given in the sample. The top sticks should be listed in order in
which they were thrown.
The picture to the right below illustrates the first case from input.
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
Top sticks: 1, 2, 3.
题意:n根stick,从第一根开始扔到平面上,第i根有可能覆盖前1-(i-1)的某些stick,求最后还有多少stick没有被覆盖.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
struct Point{
double x,y;
}p[*N]; ///叉积
double mult(Point a, Point b, Point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
} ///a, b为一条线段两端点c, d为另一条线段的两端点 相交返回true, 不相交返回false
bool isCross(Point a, Point b, Point c, Point d)
{
if (max(a.x,b.x)<min(c.x,d.x))return false;
if (max(a.y,b.y)<min(c.y,d.y))return false;
if (max(c.x,d.x)<min(a.x,b.x))return false;
if (max(c.y,d.y)<min(a.y,b.y))return false;
if (mult(c, b, a)*mult(b, d, a)<)return false;
if (mult(a, d, c)*mult(d, b, c)<)return false;
return true;
}
bool under[N]; ///记录哪些stick在下面
int ans[N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF,n){
memset(under,false,sizeof(under));
int k=;
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&p[k].x,&p[k].y,&p[k+].x,&p[k+].y);
k+=;
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(isCross(p[*i-],p[*i],p[*j-],p[*j])) {
under[i]=true;
break;
}
}
} printf("Top sticks: ");
int t=;
for(int i=;i<=n;i++){
if(!under[i]) ans[t++]=i;
}
for(int i=;i<t-;i++){
printf("%d, ",ans[i]);
}
printf("%d.\n",ans[t-]);
}
return ;
}
hdu 1147(线段相交)的更多相关文章
- hdu 1558 (线段相交+并查集) Segment set
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1558 题意是在坐标系中,当输入P(注意是大写,我当开始就wa成了小写)的时候输入一条线段的起点坐标和终点坐 ...
- hdu 1558 线段相交+并查集
题意:要求相交的线段都要塞进同一个集合里 sol:并查集+判断线段相交即可.n很小所以n^2就可以水过 #include <iostream> #include <cmath> ...
- hdu 1558 线段相交+并查集路径压缩
Segment set Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
- HDU 3492 (直线与所有线段相交) Segment
题意: 给出n个线段,判断是否存在一条直线使得所有线段在直线上的射影的交非空. 分析: 如果我们找到一条与所有线段相交的直线,然后做一条与该直线垂直的直线,这些线段在直线上的射影就一定包含这个垂足. ...
- hdu 1086(判断线段相交)
传送门:You can Solve a Geometry Problem too 题意:给n条线段,判断相交的点数. 分析:判断线段相交模板题,快速排斥实验原理就是每条线段代表的向量和该线段的一个端点 ...
- hdu 1086 You can Solve a Geometry Problem too [线段相交]
题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...
- hdu 3304(直线与线段相交)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12042 Accepted: 3808 Descrip ...
随机推荐
- MAC下Python3.5安装问题
mac中自动集成了python2.7,但是作为程序员总是希望用最新的版本, 刚才安装python3.5后,python -V,依然提示是,2.7: 然后在 .bash_profile后面找到pytho ...
- html5实现web app摇一摇换歌
微信可以摇歌曲,根据声音识别出歌曲,然后返回歌曲信息,利用html5的deviceOrientation特性和deviceMotion事件也可以在web app上实现类似于微信摇一摇的功能,原生的ap ...
- iOS-开发,拨打电话
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"te ...
- Flink on yarn的问题:Invalid AMRMToken
目前采用的Flink的版本是1.4.2,运行在yarn上,总是时不时的报错“Invalid AMRMToken from appattempt”,导致AM挂掉. 简而言之,就是AM和RM沟通的过程中, ...
- CSS继承—深入剖析
CSS的继承是指被包在内部的标签将拥有外部标签的样式性质.继承特性最典型的应用通常发挥在整个网页的样式预设,即整体布局声明.而需要要指定为其它样式的部份设定在个别元素里即可达到效果.这项特性可以给网页 ...
- P1368 工艺
题目描述 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方 ...
- loj2540 「PKUWC 2018」随机算法
pkusc 快到了--做点题涨涨 rp. 记 \(f(S,i)\) 表示 \(S\) 这个集合是决计不能选的(要么属于独立集,要么和独立集相连),或称已经考虑了的,\(i\) 表示此集合对应的最大独立 ...
- Js跑马灯效果 && 在Vue中使用
DEMO: <!DOCTYPE html><html> <head> <title>滚动播报</title> <meta charse ...
- [hdu 4348]区间修改区间查询可持久化线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4348 一开始把lazy标记给push_down了,后来发现这样会让持久化变乱,然后想到不用push_d ...
- BS架构下使用消息队列的工作流程
异步通信 对于BS(Browser-Server 浏览器)架构,很多情景下server的处理时间较长. 如果浏览器发送请求后,保持跟server的连接,等待server响应,那么一方面会对用户的体验有 ...