Pick-up sticks
来源:互联网 发布:羽西的淘宝旗舰店 编辑:程序博客网 时间:2024/06/04 19:05
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 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.
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.
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
Top sticks: 2, 4, 5.Top sticks: 1, 2, 3.
Huge input,scanf is recommended.
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<queue>#include<iomanip>//#include<bits/stdc++.h>#define eps 1e-8#define inf 0x7f//const double inf=100;using namespace std;int v[110000];struct Line{ double x1,y1,x2,y2;}line[110000];double cross(int x1,int y1,int x2,int y2,int x,int y){ return(x2-x1)*(y-y1)-(x-x1)*(y2-y1);}bool quick_check(Line a,Line b){ if(min(a.x1,a.x2)<=max(b.x1,b.x2)&&min(a.y1,a.y2)<=max(b.y1,b.y2)&&min(b.x1,b.x2)<=max(a.x1,a.x2)) return 1; return 0;}bool kua_li(Line a,Line b){ if(!quick_check(a,b)) return 0; if(cross(a.x1,a.y1,a.x2,a.y2,b.x1,b.y1)*cross(a.x1,a.y1,a.x2,a.y2,b.x2,b.y2)>=-eps) return 0; if(cross(b.x1,b.y1,b.x2,b.y2,a.x1,a.y1)*cross(b.x1,b.y1,b.x2,b.y2,a.x2,a.y2)>=-eps) return 0; return 1;}int main(){ int n; while(~scanf("%d",&n)&&n) { memset(v,0,sizeof(v)); for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&line[i].x1,&line[i].y1,&line[i].x2,&line[i].y2); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(kua_li(line[i],line[j])) { v[i]=1; break; } } } printf("Top sticks: "); int p=0; for(int i=0;i<n;i++) { if(v[i]==0) { if(p==0) { printf("%d",i+1); p++; } else printf(", %d",i+1); } } printf(".\n"); }}
阅读全文
0 0
- Pick-up Sticks
- poj2653 - Pick-up sticks
- POJ Pick-up sticks
- Pick-up sticks
- Pick-up sticks
- POJ2653 Pick-up sticks
- POJ2653-Pick-up sticks
- poj2653-Pick-up sticks
- hdu1147:pick up sticks
- hdu1147(Pick-up sticks)
- poj2653 Pick-up sticks
- Pick-up sticks
- poj2653 Pick-up sticks
- Pick-up sticks
- Pick-up sticks
- poj2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- hdu 2497 Pick up sticks
- SPRY框架,Web前端开发效率的利器
- 学习:图片标注工具LabelImg使用教程
- 数字货币开发教程的智能合约demo解析
- netbeans-8.zip
- 无穷小微积分:发源于西方,扎根在中国
- Pick-up sticks
- package.json文件中的^和~的区别
- Android App监听软键盘按键的三种方式 以及 输入法删除退格键的冲突问题解决
- WebService
- Dao设计模式
- java设计模式总结八:代理模式
- "=="和equals方法究竟有什么区别?
- 急!在线等!遥控钥匙没电了怎么办?
- unity 遮挡剔除