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

5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0

Sample Output

Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.

Hint

Huge input,scanf is recommended.

Source

 
 

题解:

  几何模板题目

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0001
const LL INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
int n, cnt;
struct POINT
{
double x, y, z;
POINT():x(), y(), z(){};
POINT(double _x_, double _y_, double _z_ = ):x(_x_), y(_y_), z(_z_) {};
};
struct SEG
{
POINT a;
POINT b;
SEG(){};
SEG(POINT _a_, POINT _b_):a(_a_),b(_b_) {};
};
double Cross(const POINT &a, const POINT & b, const POINT &o)//叉乘
{
return (a.x - o.x)*(b.y - o.y) - (b.x - o.x)*(a.y - o.y);
}
bool IsIntersect(const SEG &u, const SEG &v)
{
return (Cross(v.a, u.b, u.a)*Cross(u.b, v.b, u.a)>=)&&
(Cross(u.a, v.b, v.a)*Cross(v.b, u.b, v.a)>=)&&
(max(u.a.x, u.b.x) >= min(v.a.x, v.b.x))&&
(max(v.a.x, v.b.x) >= min(u.a.x, u.b.x))&&
(max(u.a.y, u.b.y) >= min(v.a.y, v.b.y))&&
(max(v.a.y, v.b.y) >= min(u.a.y, u.b.y));
}
int ans[maxn];
SEG stick[maxn];
void init()
{
cnt = ;
}
void solve() {
double a, b, c, d;
for(int i = ;i<=n;i++){
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
stick[i].a.x=a;stick[i].a.y=b;
stick[i].b.x=c;stick[i].b.y=d;
}
for(int i = n;i>;i--){
bool flag = ;
for(int j = i+;j<=n;j++){
if(IsIntersect(stick[i], stick[j])){
flag = ;
break;
}
}
if(flag){
ans[cnt++] = i;
}
if(cnt>=){
break;
}
}
printf("Top sticks:");
for(int i = cnt-;i>=;i--){
if(i==) printf(" %d.",ans[i]);
else printf(" %d,",ans[i]);
}
printf("\n");
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
while(~scanf("%d", &n)&&n){
init();
solve();
}
return ;
}

POJ 2653 Pick-up sticks(几何)的更多相关文章

  1. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

  2. 线段相交 POJ 2653

    // 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...

  3. poj 2653 线段与线段相交

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11884   Accepted: 4499 D ...

  4. 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 ...

  5. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  6. CDOJ 1218 Pick The Sticks

    Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  7. 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 ...

  8. POJ 2653 Pick-up sticks --队列,几何

    题意: 按顺序扔木棒,求出最上层的木棒是哪些. 解法: 由于最上层的木棒不超过1000个,所以用一个队列存储最上层的木棒,每次扔出一个木棒后,都与队列中的木棒一一判断,看此木棒是否在某一最上层的木棒的 ...

  9. 简单几何(线段相交) POJ 2653 Pick-up sticks

    题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...

随机推荐

  1. GitHub Pages建立第一个静态页面

    1.创建仓库 创建仓库点击右上角的加号,选择newrepository.然后对仓库信息进行设置.注意箭头标识的几个地方.仓库名必须是http://username.github.io的形式.必须勾选p ...

  2. [19/05/08-星期三] JDBC(Java DataBase Connectivity)_ORM(Object Relationship Mapping, 对象关系映射)

    一.概念 基本思想: – 表结构跟类对应: 表中字段和类的属性对应:表中记录和对象对应: – 让javabean的属性名和类型尽量和数据库保持一致! – 一条记录对应一个对象.将这些查询到的对象放到容 ...

  3. SpringBoot(五) -- SpringBootWeb登录示例

    一.解决index.html访问 在SpringBoot中默认访问的首页是静态资源文件夹下的index.html,无法被Thymeleaf模板引擎解析,因此我们可以定义一个controller将默认请 ...

  4. poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10940   Accepted:  ...

  5. 一个阿里云apache服务器配置两个或多个域名forLinux

    一个阿里云apache服务器配置两个或多个域名for Linux: 默认已经配置好了阿里云提供的一键web安装,可以参考:http://www.42iot.com/?id=8 修改/alidata/s ...

  6. poj_3179 Corral the Cows (二分+二维前缀和+离散化)

    [题目链接] http://poj.org/problem?id=3179 [参考] http://www.cnblogs.com/evenbao/p/9243183.html [算法] 二分答案+判 ...

  7. sql 时间函数大全

    1.        当前系统日期.时间    select getdate() 2. dateadd  在向指定日期加上一段时间的基础上,返回新的 datetime 值  例如:向日期加上2天  se ...

  8. python学习笔记(11):文件的访问与函数式编程

    一.文本文件读写的三种方法 1.直接读入 file1 = open('E:/hello/hello.txt') file2 = open('output.txt','w') #w是可写的文件 whil ...

  9. map集合中取出分类优先级最高的类别名称

    import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map ...

  10. mybatis resultMap之collection聚集两种实现方式

    最近做得项目用到了MyBatis处理一对多的映射关系,下面的两个方法中用到了集合的嵌套查询方法,下面仔细学习一下这两种方式 聚集元素用来处理"一对多"的关系.需要指定映射的Java ...