HDU 1147 /// 判断两线段相交
题目大意:
给定n条线段的端点
依次放上n条线段 判断最后在最上面(不被覆盖)的线段有哪些
到当前线段后 直接与之前保存的未被覆盖的线段判断是否相交就可以了
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <set>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std; const double eps=1e-;
double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
struct P {
double x,y;
P(){};
P(double _x,double _y):x(_x),y(_y){}
P operator - (P p) { return P(add(x,-p.x),add(y,-p.y)); }
P operator + (P p) { return P(add(x,p.x),add(y,p.y)); }
P operator * (double d) { return P(x*d,y*d); }
bool operator == (P p) { return x==p.x && y==p.y; }
bool operator < (P p) {
if(x==p.x) return y<p.y;
return x<p.x;
}
double dot(P p) { return add(x*p.x,y*p.y); }
double det(P p) { return add(x*p.y,-y*p.x); }
}p[];
int n;
set <int> s;
bool vis[]; P ins(P a,P b,P c,P d) {
return a+(b-a)*((c-d).det(d-a)/(c-d).det(b-a));
}
bool onSeg(P a,P b,P c) {
return (a-c).det(b-c)== && (a-c).dot(b-c)<=;
}
bool insSS(P a,P b,P c,P d)
{
if((a-b).det(c-d)==) {
return onSeg(a,b,c) || onSeg(a,b,d)
|| onSeg(c,d,a) || onSeg(c,d,b);
}
else {
P r=ins(a,b,c,d);
return onSeg(a,b,r) && onSeg(c,d,r);
}
} int main()
{
while(~scanf("%d",&n)) {
if(n==) break;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i+n].x,&p[i+n].y);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
if(insSS(p[i],p[i+n],p[j],p[j+n])) {
vis[i]=; break;
}
bool yes=;
printf("Top sticks:");
for(int i=;i<=n;i++) {
if(vis[i]) continue;
if(yes) printf(", %d",i);
else yes=, printf(" %d",i);
}
printf(".\n");
} return ;
}
HDU 1147 /// 判断两线段相交的更多相关文章
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- poj 1127:Jack Straws(判断两线段相交 + 并查集)
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2911 Accepted: 1322 Descr ...
- hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
- TOJ1840: Jack Straws 判断两线段相交+并查集
1840: Jack Straws Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Submit: 1 ...
- POJ_1227 Jack Straws 【二维平面判两线段相交】
一 题面 POJ1127 二 分析 在平面几何中,判断两线段相交的方法一般是使用跨立实验.但是这题考虑了非严格相交,即如何两个线段刚好端点相交则也是相交的,所以还需要使用快速排斥实验. 这里参考并引用 ...
- ACM1558两线段相交判断和并查集
Segment set Problem Description A segment and all segments which are connected with it compose a seg ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
随机推荐
- HTML——表格标签
存在即是合理的. 表格的现在还是较为常用的一种标签,但不是用来布局,常见处理.显示表格式数据. 创建表格 在HTML网页中,要想创建表格,就需要使用表格相关的标签.创建表格的基本语法格式如下: < ...
- linux下df查看空间已经占用%100,但是找不到大文件的解决方法
有时候在linux下会遇到这种情况:df查看空间已经占用%100,但是找不到大文件,怎么回事呢,经过网上查找资料,得到解决方法: 1.使用lsof查看已删除但未释放的文件 lsof -n | grep ...
- Harbor任意管理员注册漏洞复现CVE-2019-16097
注册时抓包 添加poc "has_admin_role":true 管理员权限 POC POST /api/users HTTP/1.1 Host: 127.0.0.1 Conte ...
- static 关键字的使用及说明
static 关键字主要有以下几种使用场景: 修饰类的成员变量. 修饰类的成员方法. 修饰类的代码块. 修饰内部类. 1. static 修饰类的成员变量时,被称为静态成员变量.引用 static 修 ...
- Auto.js淘宝领喵币
最近,淘宝的新玩法,一直在充斥我的眼球,尤其是喵币的,盖楼... .... 于是就进去看了看,发现逛逛店铺,给好多喵币,但是要进20个,每个要15秒,好麻烦,于是就上网搜了一下,有没有脚本 因为之前搞 ...
- python 17 函数基础(一)
http://www.cnblogs.com/BeginMan/p/3171977.html 一.什么是函数.方法.过程 推荐阅读:http://www.cnblogs.com/snandy/arch ...
- 第三天:字典表dict、元组tuple、文件与类型汇总
1.字典表dict 声明 {键: 值,...} dict(键=值) d = {'isbn':'13123','title':'python入门'} #字典表中的键不能使用诸如列表这种可以改变的,只能使 ...
- Neo4j和Elasticsearch
Neo4j和Elasticsearch Neo4j和Elasticsearch是一种让人眼前一亮的组合,为什么需要把搜索和图表结合起来呢?它们是如何使用的呢? 在无处不在的互联网搜索引擎的推动下,全文 ...
- vue解决sass-loader的版本过高导致的编译错误
Module build failed: TypeError: this.getResolve is not a function at Object.loader (E:\appEx\PreRese ...
- http协议 头部字段 referrer
学习笔记,非原创,抄自:https://www.cnblogs.com/amyzhu/p/9716493.html:https://blog.csdn.net/java_zhangshuai/arti ...