博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Pick-up sticks(判断两直线相交)
阅读量:6320 次
发布时间:2019-06-22

本文共 2204 字,大约阅读时间需要 7 分钟。

Pick-up sticks
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 11335   Accepted: 4250

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.

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. 题解:这个题是让找出与其他直线不交或者在其他直线最上面的直线; 判断相交,两个直线的一个端点都要判断; 代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #define mem(x,y) memset(x,y,sizeof(x)) 7 using namespace std; 8 typedef long long LL; 9 const int INF=0x3f3f3f3f;10 const int MAXN=100010<<1;11 struct Point{12 double x,y;13 Point(double x=0,double y=0):x(x),y(y){}14 };15 typedef Point Vector;16 Point dt[MAXN];17 Vector operator - (Point a,Point b){
return Vector(a.x-b.x,a.y-b.y);}18 double Cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;}19 int main(){20 int n,k,j;21 while(scanf("%d",&n),n){22 k=0;23 for(int i=1;i<=n;i++)24 scanf("%lf%lf%lf%lf",&dt[i].x,&dt[i].y,&dt[i+n].x,&dt[i+n].y);25 printf("Top sticks: ");26 for(int i=1;i

 

转载地址:http://mwcaa.baihongyu.com/

你可能感兴趣的文章
019-直接利用Socket/TCP开发网络游戏二
查看>>
Java集合之ArrayList
查看>>
python的标准数据类型
查看>>
Android 那些年踩过的坑
查看>>
消息handler message 线程通信 空消息
查看>>
scrapy 按顺序抓取text内容
查看>>
软技能(面试)1
查看>>
The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack
查看>>
【linux】保存屏幕日志log
查看>>
记一道经典前端题
查看>>
iOS走近商城APP(二 购物车常用控件)
查看>>
使用 Kafka 和 MongoDB 进行 Go 异步处理
查看>>
禁止自动横屏下的视频播放强制旋转
查看>>
Docker 入门操作
查看>>
直播的一些技术点
查看>>
JavaScript实现链表
查看>>
103. Binary Tree Zigzag Level Order Traversal
查看>>
JavaScript函数式编程,真香之组合(一)
查看>>
使用Envoy 作Sidecar Proxy的微服务模式-3.分布式追踪
查看>>
深入了解以太坊
查看>>