POJ 2653 Pick-up sticks(判断线段相交)
来源:互联网 发布:酷听说软件问题 编辑:程序博客网 时间:2024/04/29 17:20
Pick-up sticks
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 13161 Accepted: 4947
Description
Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.
Input
Input consists of a number of cases. The data for each case start with 1 <= n <= 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is ended by the case with n=0. This case should not be processed.
Output
For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown.
The picture to the right below illustrates the first case from input.
The picture to the right below illustrates the first case from input.
Sample Input
51 1 4 22 3 3 11 -2.0 8 41 4 8 23 3 6 -2.030 0 1 11 0 2 12 0 3 10
Sample Output
Top sticks: 2, 4, 5.Top sticks: 1, 2, 3.
Hint
Huge input,scanf is recommended.
题意:依次放下n条木棒,问最上面没被挡住的木棒有几根
思路:从前往后判断前面的直线有没有被后面的直线挡住
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstring>#include<string>#include<algorithm>using namespace std;#define ll long long#define ms(a,b)memset(a,b,sizeof(a))#define eps 1e-10#define inf 1e8int n,m,cntl,cntp;double add(double a,double b){ if(abs(a+b)<eps*(abs(a)+abs(b))) return 0; 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); } 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[100005],q[100005];bool on_seg(P p1,P p2,P q){ return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;}P intersection(P p1,P p2,P q1,P q2){ return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));}bool xiangjiao(P p1,P p2,P p3,P p4){ P r=intersection(p1,p2,p3,p4); if(on_seg(p1,p2,r)&&on_seg(p3,p4,r)) return true; return false;}bool flag[100005];int ans[1005];int main(){ while(~scanf("%d",&n)) { if(n==0) break; int cnt=0; for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&q[i].x,&q[i].y); flag[i]=1; } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(xiangjiao(p[i],q[i],p[j],q[j])) { flag[i]=0; break; } } } printf("Top sticks: "); bool first = true; for(int i = 1;i <= n;i++) if(flag[i]) { if(first)first = false; else printf(", "); printf("%d",i); } printf(".\n"); } return 0;}
阅读全文
0 0
- poj 2653 Pick-up sticks(判断线段是否相交)
- poj 2653 Pick-up sticks(判断线段是否相交)
- POJ 2653 Pick-up sticks (判断线段相交)
- POJ 2653 Pick-up sticks(判断线段相交)
- poj 2653 Pick-up sticks(判断线段相交)
- POJ 2653 Pick-up sticks(判断线段相交)
- POJ 2653 Pick-up sticks(判断线段相交)
- POJ 2653 Pick-up sticks 枚举判断线段是否相交
- POJ 2653 Pick-up sticks 判断线段相交
- poj 2653 Pick-up sticks(几何线段相交判断)
- POJ 2653 Pick-up sticks (判断线段相交)
- POJ 2653 Pick-up sticks【判断线段相交】
- POJ 2653 Pick-up sticks 判断线段相交
- poj 2653 Pick-up sticks(判断线段相交)
- POJ 2653 Pick-up sticks(判断线段相交)
- Pick-up sticks(线段相交判断)
- 【poj 2653】 Pick-up sticks 线段相交
- poj 2653 Pick-up sticks 线段相交
- 神经网络训练细节之batch normalization
- 计算机基础知识:什么是位、字节、字、KB、MB
- iOS 真机调试、打包测试、发布程序常见问题
- 面试题目
- C# 多线程学习(一)多线程的概念
- POJ 2653 Pick-up sticks(判断线段相交)
- 【stm32f407】SD协议(一)-SDIO
- Android中一个Activity关闭另一个Activity或者在一个Activity中关闭多个Activity
- MediaPlayer对象从停止状态到播放状态调用的方法是prepare()和start()
- Android中View的相关知识(8)
- Tomcat源码分析(三)------ Request和Response处理的全过程
- Linux运维 -- day02 配置ip地址
- 排序算法学习笔记(sorting algorithms)
- 比赛