[poj2653]Pick-up sticks
题目大意:给定一系列线段,以及放在平面上的顺序,给出没有被其他覆盖的线段。
解题关键:线段相交的判断。
满足两个条件即可:快速排斥实验、跨立实验。
#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的更多相关文章
- 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 ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- CDOJ 1218 Pick The Sticks
Pick The Sticks Time Limit: 15000/10000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- 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 ...
- POJ2653:Pick-up sticks(线段相交)
题目:http://poj.org/problem?id=2653 题意:题意很简单,就是在地上按顺序撒一对木棒,看最后有多少是被压住的,输出没有被压住的木棒的序号.(有点坑的就是没说清楚木棒怎么算压 ...
- UESTC 1218 Pick The Sticks
Time Limit: 15000/10000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status ...
- hdu 5543 Pick The Sticks(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:给你一根长为m的长木板和一些小木棒,每一根小木棒有它的长度和价值,这些小木棒要放在长木板上 ...
- DP(01背包) UESTC 1218 Pick The Sticks (15CCPC C)
题目传送门 题意:长度为L的金条,将n根金棍尽可能放上去,要求重心在L上,使得价值最大,最多有两条可以长度折半的放上去. 分析:首先长度可能为奇数,先*2.然后除了两条特殊的金棍就是01背包,所以dp ...
- [HDOJ5543]Pick The Sticks(DP,01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...
- uestc oj 1218 Pick The Sticks (01背包变形)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
随机推荐
- linux查看网卡速度
ethtool eth0 会包含速度模式等各项属性信息 lspci|grep -i ether 可以查看硬件设备具体型号,会包含硬件厂商及信息 dmesg |grep -i eth 会显示系统 ...
- 基于RTP协议的H.264传输
1. 引言 随 着信息产业的发展,人们对信息资源的要求已经逐渐由文字和图片过渡到音频和视频,并越来越强调获取资源的实时性和互动性.但人们又面临着另外一种不可避免 的尴尬,就是在网络上看 ...
- redhat5.8 alt+ctrl+f1 黑屏
/********************************************************************** * redhat5.8 alt+ctrl+f1 黑屏 * ...
- Aixs2发布webservice服务
http://www.blogjava.net/pzxsheng/archive/2012/12/21/393319.html 开发前准备: 1.Eclipse Java EE IDE(Juno ...
- flash、js 函数 互相调用
js调用flex函数 flex 利用ExternalInterface.addCallback(“注册的方法名”,As中的函数名)进行注册 js中,用document.getElementById(“ ...
- Technocup 2019 C. Compress String
一个字符串 $s$,你要把它分成若干段,有两种合法的段 1.段长为 $1$,代价为 $a$ 2.这个段是前面所有段拼起来组成的字符串的字串,代价为 $b$ 问最小代价 $|s| \leq 5000$ ...
- hdu 1937 Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 团队队列(列和map结合的经典运用)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- npm镜像安装
安装淘宝NPM镜像 https://npm.taobao.org/ npm install -g cnpm --registry=https://registry.npm.taobao.org 配置 ...
- MMS(mongodb监控工具)
今天好几个人问我如何查看mongodb的连接数,在mongo shell中执行: shard1:PRIMARY> db.serverStatus().connections { "cu ...