博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2653 Pick-up sticks(几何)
阅读量:6329 次
发布时间:2019-06-22

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

Pick-up sticks
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 13377   Accepted: 5039

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.

Hint

Huge input,scanf is recommended.

Source

 
 

题解:

  几何模板题目

  

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 using namespace std;13 typedef long long LL;14 #define ms(a, b) memset(a, b, sizeof(a))15 #define pb push_back16 #define mp make_pair17 #define eps 0.000118 const LL INF = 0x7fffffff;19 const int inf = 0x3f3f3f3f;20 const int mod = 1e9+7;21 const int maxn = 100000+10;22 int n, cnt;23 struct POINT24 {25 double x, y, z;26 POINT():x(0), y(0), z(0){};27 POINT(double _x_, double _y_, double _z_ = 0):x(_x_), y(_y_), z(_z_) {};28 };29 struct SEG30 {31 POINT a;32 POINT b;33 SEG(){};34 SEG(POINT _a_, POINT _b_):a(_a_),b(_b_) {};35 };36 double Cross(const POINT &a, const POINT & b, const POINT &o)//叉乘37 {38 return (a.x - o.x)*(b.y - o.y) - (b.x - o.x)*(a.y - o.y);39 }40 bool IsIntersect(const SEG &u, const SEG &v)41 {42 return (Cross(v.a, u.b, u.a)*Cross(u.b, v.b, u.a)>=0)&&43 (Cross(u.a, v.b, v.a)*Cross(v.b, u.b, v.a)>=0)&&44 (max(u.a.x, u.b.x) >= min(v.a.x, v.b.x))&&45 (max(v.a.x, v.b.x) >= min(u.a.x, u.b.x))&&46 (max(u.a.y, u.b.y) >= min(v.a.y, v.b.y))&&47 (max(v.a.y, v.b.y) >= min(u.a.y, u.b.y));48 }49 int ans[maxn];50 SEG stick[maxn];51 void init()52 {53 cnt = 0;54 }55 void solve() {56 double a, b, c, d;57 for(int i = 1;i<=n;i++){58 scanf("%lf%lf%lf%lf", &a, &b, &c, &d);59 stick[i].a.x=a;stick[i].a.y=b;60 stick[i].b.x=c;stick[i].b.y=d;61 }62 for(int i = n;i>0;i--){63 bool flag = 1;64 for(int j = i+1;j<=n;j++){65 if(IsIntersect(stick[i], stick[j])){66 flag = 0;67 break;68 }69 }70 if(flag){71 ans[cnt++] = i;72 }73 if(cnt>=1000){74 break;75 }76 }77 printf("Top sticks:");78 for(int i = cnt-1;i>=0;i--){79 if(i==0) printf(" %d.",ans[i]);80 else printf(" %d,",ans[i]);81 }82 printf("\n");83 }84 int main() {85 #ifdef LOCAL86 freopen("input.txt", "r", stdin);87 // freopen("output.txt", "w", stdout);88 #endif89 while(~scanf("%d", &n)&&n){90 init();91 solve();92 }93 return 0;94 }
View Code

 

转载于:https://www.cnblogs.com/denghaiquan/p/7223237.html

你可能感兴趣的文章
波形捕捉:(3)"捕捉设备"性能
查看>>
AliOS Things lorawanapp应用介绍
查看>>
美国人的网站推广方式千奇百怪
查看>>
java web学习-1
查看>>
用maven+springMVC创建一个项目
查看>>
linux设备驱动第四篇:以oops信息定位代码行为例谈驱动调试方法
查看>>
redis知识点整理
查看>>
Hello World
查看>>
Spring3全注解配置
查看>>
ThreadLocal真会内存泄露?
查看>>
IntelliJ IDEA
查看>>
低版本mybatis不能用PageHeper插件的时候用这个分页
查看>>
javaweb使用自定义id,快速编码与生成ID
查看>>
[leetcode] Add Two Numbers
查看>>
elasticsearch suggest 的几种使用-completion 的基本 使用
查看>>
04-【MongoDB入门教程】mongo命令行
查看>>
Hadoop HA元数据备份
查看>>
字符串与整数之间的转换
查看>>
断点传输HTTP和URL协议
查看>>
redis 数据类型详解 以及 redis适用场景场合
查看>>