题目大意:给定一系列线段,以及放在平面上的顺序,给出没有被其他覆盖的线段。

解题关键:线段相交的判断。

满足两个条件即可:快速排斥实验、跨立实验。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
const double eps=1e-;
int sgn(double x){
if(fabs(x)<eps)return ;
else if(x<) return -;
else return ;
}
struct Point{
double x,y;
Point(){}
Point(double _x,double _y){x=_x;y=_y;}
Point operator-(const Point &b)const{return Point(x - b.x,y - b.y);}
double operator^(const Point &b)const{return x*b.y-y*b.x;}
double operator*(const Point &b)const{return x*b.x+y*b.y;}
};
struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){s=_s;e=_e;}
};
//判断线段相交,模板
bool inter(Line l1,Line l2){
return
max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x)&&
max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x)&&
max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y)&&
max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y)&&
sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s))<=&&
sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s))<=;
} const int MAXN=;
Line line[MAXN];
bool flag[MAXN];
int main(){
int n;
double x1,y1,x2,y2;
while(scanf("%d",&n),n){
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[i]=Line(Point(x1,y1),Point(x2,y2));
flag[i]=true;
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++)
if(inter(line[i],line[j])){
flag[i]=false;
break;
}
}
printf("Top sticks: ");
bool first=true;
for(int i=;i<=n;i++)
if(flag[i]){//只是为了控制格式
if(first)first=false;
else printf(", ");
printf("%d",i);
}
printf(".\n");
} return ;
}

[poj2653]Pick-up sticks的更多相关文章

  1. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  2. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  3. CDOJ 1218 Pick The Sticks

    Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  4. 2015南阳CCPC D - Pick The Sticks 背包DP.

    D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...

  5. POJ2653:Pick-up sticks(线段相交)

    题目:http://poj.org/problem?id=2653 题意:题意很简单,就是在地上按顺序撒一对木棒,看最后有多少是被压住的,输出没有被压住的木棒的序号.(有点坑的就是没说清楚木棒怎么算压 ...

  6. UESTC 1218 Pick The Sticks

    Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status ...

  7. hdu 5543 Pick The Sticks(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:给你一根长为m的长木板和一些小木棒,每一根小木棒有它的长度和价值,这些小木棒要放在长木板上 ...

  8. DP(01背包) UESTC 1218 Pick The Sticks (15CCPC C)

    题目传送门 题意:长度为L的金条,将n根金棍尽可能放上去,要求重心在L上,使得价值最大,最多有两条可以长度折半的放上去. 分析:首先长度可能为奇数,先*2.然后除了两条特殊的金棍就是01背包,所以dp ...

  9. [HDOJ5543]Pick The Sticks(DP,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...

  10. uestc oj 1218 Pick The Sticks (01背包变形)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...

随机推荐

  1. 开发一个app需要多少钱

    App应用开发是目前最热门的产业,很多企业都想通过app的开发来进入移动互联网市场分一杯羹. 那么你一定很想知道开发一个app需要多少钱吧?那下面企业帮就来帮大家计算一下费用吧. 面对app抄袭成风的 ...

  2. webpack vue-cli 一有空格和分号就报错

    webpack vue-cli 一有空格和分号就报错 eslintrc.js 这是ESLint的配置文件,至于为什么用ESLint的话,就是为了自动检查代码,保持一致的代码风格,从而保证代码质量. 这 ...

  3. 解析Ceph: 恢复与数据一致性

    转自:https://www.ustack.com/blog/ceph-internal-recovery-and-consistency/ 作为一个面向大规模的分布式存储系统,故障处理是作为一个常态 ...

  4. LeetCode OJ:Construct Binary Tree from Preorder and Inorder Traversal(从前序以及中序遍历结果中构造二叉树)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  5. 详解linux互斥锁 pthread_mutex和条件变量pthread_cond

    [cpp] view plaincopy ============================================================= int pthread_creat ...

  6. [TopCoder12727]FoxAndCity

    vjudge 题意 你有一张\(n\)点的无向图,每个点有一个点权\(w_i\).图中原来存在一些边,你可以任意给这张图加上一些边. 记点\(i\)到点\(1\)的距离为\(d_i\),你需要最小化\ ...

  7. Entity Framework中AutoDetectChangesEnabled為false時更新DB方法

    Entity Framework初始化時執行: Configuration.AutoDetectChangesEnabled = false; 會將數據庫變為NotTrack模式,也就是不會自動同步对 ...

  8. java代码----方法类练习中~~~未领会

    总结:今天我很失败,问了老师继承的问题还是没弄懂.因为,技术宅的能力,我好怕啊.太强了. package com.da.ima2; public class yut {// 使用substring方法 ...

  9. Breaking Good

    Time limit2000 ms Memory limit262144 kB Breaking Good is a new video game which a lot of gamers want ...

  10. 杂项:MIME(多用途互联网邮件扩展类型)百科

    ylbtech-杂项:MIME(多用途互联网邮件扩展类型)百科 MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用 ...