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. loadrunner+win2003虚拟机的安装

    lr11的安装和使用 准备材料: 1.win2003镜像下载 2.虚拟机下载 3.lr11的下载 一.创建win2003虚拟机 打开虚拟机,选择win2003系统镜像,输入密钥(可百度),用户名密码( ...

  2. python_001

    一.python开发1.python基础 -基础 -基本数据类型 -函数 -面向对象2.网络编程3.web框架 -用于写网站4.设计模式 + 算法

  3. ecshop启用gzip后,后台不能打开不能访问的问题

    上传测试的时候,站点显示无法打开.随后我用网址打开根目录的robots文件.图片.静态页···全部可以正常打开··· 我尴尬···一一检查后,我就怀疑是不是客户当初设置gzip压缩的问题了.但连后台都 ...

  4. ubuntu 上用virtualenv安装python不同版本的开发环境。

    1.用pip安装virtualenv apt-get install python-virtualenv 2.创建python2的虚拟环境,进入要创建虚拟环境的目录下,我是放在/home/pyenv/ ...

  5. [Git] 012 rm 命令的补充

    0. 前言 [Git] 007 三棵树以及向本地仓库加入第一个文件 的 "2.5" 有提及 git rm --cached <file> 1. 介绍 git rm &l ...

  6. [Python3 练习] 006 汉诺塔2 非递归解法

    题目:汉诺塔 II 接上一篇 [Python3 练习] 005 汉诺塔1 递归解法 这次不使用递归 不限定层数 (1) 解决方式 利用"二进制" (2) 具体说明 统一起见 我把左 ...

  7. squid代理服务问答

    1. 简述一下squid的用途?squid可以做代理和缓存服务器,而做代理时,可以分为正向代理和反向代理.正向代理用在企业办公环境中,企业员工上网通过代理来上网,代理的缓存功能可以为企业节省宝贵的带宽 ...

  8. CentOS6 破解登录密码

    1.重启服务器,在倒数读秒的时候按任意键,就会出现如下界面 2.按e进入grub模式,选中kernel,然后按e进入内核编辑模式 3.进入内核编辑模式后,按空格+1回车(或按空格+single回车)退 ...

  9. HDFS中NameNode发生故障没有备份从SecondNameNode恢复

    1.Secondary NameNode目录结构 Secondary NameNode用来监控HDFS状态的辅助后台程序,每隔一段时间获取HDFS元数据的快照. 在/opt/module/hadoop ...

  10. HDU-6187.DestroyWalls(最大生成树)

    好吧这个题没什么可说的,有点.... 一开始还和一位大佬在讨论,会不会有多余的边,后面看了题发现没有多于的边和自环,所以之间一波最大生成树把最大的边去掉,把最小的边推倒就行了. #include &l ...