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的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
随机推荐
- Java——子类对象实例化的全过程
2.4子类对象实例化的全过程 public class TestDog { public static void main(String[] args) { Dog d = new Dog(); d. ...
- 仿淘宝使用flex布局实现页面顶部和底部的固定布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- NX二次开发-UFUN选择草图对话框UF_UI_select_sketch
#include <uf.h> #include <uf_ui.h> UF_initialize(); //选择草图对话框 char sMessage[] = "选择 ...
- 牛客多校第七场 C Governing sand 线段树
题意: 有一个树林,树林中不同种类的树有不同的数量,高度,砍伐它们的价格.现在要求砍掉一些树,使得高度最高的树占剩下的树的总数的一半以上,求最小花费. 题解: 用线段树维护不同种类树的信息,叶子节点从 ...
- 3、发送第一个api请求
接口地址:https://www.v2ex.com/api/topics/latest.json Method: GET Authentication: None 我们打开postman,方法选择ge ...
- Android Telephony分析(二) ---- RegistrantList详解
前言 本文主要讲解RegistrantList的原理,以及如何快速分析RegistrantList相关的代码流程.在Telephony模块中,在RIL.Tracker(ServiceStateTrac ...
- 2.用Python套用Excel模板,一键完成原亮样式
from xlutils.copy import copy import xlrd import xlwt tem_excel=xlrd.open_workbook('日统计.xls',formatt ...
- Redis事务,持久化,哨兵机制
1 Redis事务 基本事务指令 Redis提供了一定的事务支持,可以保证一组操作原子执行不被打断,但是如果执行中出现错误,事务不能回滚,Redis未提供回滚支持. multi 开启事务 exec 执 ...
- 树形结构_红黑树:平衡2X 哈夫曼树:最优2X
红黑树:平衡2X 哈夫曼树:最优2X 红黑树 :TreeSet.TreeMap 哈夫曼树 1. 将w1.w2.…,wn看成是有n 棵树的森林(每棵树仅有一个结点): 2. 在森林中选出根结点的权值最小 ...
- iOS开发系列-打印内存地址
打印内存地址 基本数据类型 定义一个基本数据类型,会根据变量类型分配对应的内存空间.比如定义一个int类型的变量a. int a = 10; 内存如下 输入变量a在内存中内存地址 NSLog(@&qu ...