题目大意:

给定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 /// 判断两线段相交的更多相关文章

  1. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. 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 ...

  3. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  4. 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 ...

  5. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  6. TOJ1840: Jack Straws 判断两线段相交+并查集

    1840: Jack Straws  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Submit: 1 ...

  7. POJ_1227 Jack Straws 【二维平面判两线段相交】

    一 题面 POJ1127 二 分析 在平面几何中,判断两线段相交的方法一般是使用跨立实验.但是这题考虑了非严格相交,即如何两个线段刚好端点相交则也是相交的,所以还需要使用快速排斥实验. 这里参考并引用 ...

  8. ACM1558两线段相交判断和并查集

    Segment set Problem Description A segment and all segments which are connected with it compose a seg ...

  9. HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)

    题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...

随机推荐

  1. 几道51nod上据说是提高组难度的dp题

    1409 加强版贪吃蛇 听着懵逼做着傻逼. 每个格子只能经过一次,穿过上下界答案清0,不考虑穿的话就随便dp.如果要穿就是从尽可能上面的位置穿过上界,尽可能下面的位置穿过下界. 那么转移这一列之前找一 ...

  2. C++ 将汉字转换成拼音全拼【转载】

    转载自https://www.cnblogs.com/mzhrd/p/4758105.html #include <string> using std::string; //======= ...

  3. Spring Boot 遇到空指针

    @Autowired private IRoadRescueService roadRescueService; 千万不要把注入的service类设为static

  4. iOS开发之UIMenuController

    1.简介 用于剪切.复制.粘贴.选择.选择ALL和DELETE命令的菜单界面. UITextField.UIWebView.UITextView自带有这种UIMenuController效果: 2.相 ...

  5. C4D中python初探

    use_name = input('请输入账号') password = input('请输入密码') if use_name == 'alex' and password == 'alex3714' ...

  6. JPA Query in 集合

    使用 :param的方式来传递参数,下面举个例子 @PersistenceContext ​​​​​​​EntityManager em @Override public List<Map> ...

  7. redis config

    网络上抄袭过来的 然后顺序自己做点笔记 http://chembo.iteye.com/blog/2054021 这里有各个key 详细的描述 # redis 配置文件示例 # 当你需要为某个配置项指 ...

  8. python库之xgboost

    一.安装 https://www.zhihu.com/question/46377605

  9. 校园商铺-4店铺注册功能模块-6店铺注册之Controller层的实现

    1. 从request请求获取获取相关的值 HttpservletRequest request代表的是客户端的请求.当客户端通过http协议访问服务器的时候,http请求头中的所有信息,都封装在这个 ...

  10. Jmeter插件:jp@gc - Dummy Sampler

    Dummy Sampler可以比较方便地模拟测试场景,自定义Request Data和Response Data 1. 安装插件:打开页面插件管理网站,下载plugins-manager.jar. 在 ...