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. 阅读笔记12-Java 面试题 —— 老田的蚂蚁金服面试经历

    电话一面 1.自我介绍.自己做的项目和技术领域 2.项目中的监控:那个监控指标常见的哪些? 3.微服务涉及到的技术以及需要注意的问题有哪些? 4.注册中心你了解了哪些? 5.consul 的可靠性你了 ...

  2. 关于服务器无法在已发送http表头之后设置状态问题

    Response.ClearHeaders()方法 ClearHeaders方法只删除头信息,而不删除Response显示输出信息. this.Response.BufferOutput = true ...

  3. 事件 on emit off 封装

    /* on 绑定 emit 触发 off 解绑 //存放事件 eventList = { key:val handle:[] } 1对多 on(eventName,callback); handle: ...

  4. Java相关面试题总结+答案(九)

    [MySQL] 164. 数据库的三范式是什么? 第一范式:强调的是列的原子性,即数据库表的每一列都是不可分割的原子数据项. 第二范式:属性完全依赖于主键(满足第一范式的前提下),即任意一个字段只依赖 ...

  5. Kafka DockerFile

    FROM php:5.6.38-fpm COPY . /alidata/workerspace WORKDIR /alidata/workerspace RUN set -x && a ...

  6. windows 10 自动升级后环境变量无效

    上个礼拜放假的时候,win10提示需要升级,我当时随手就一点更新并关机...今天,在启动项目时候尴尬了: D:\project\js\iam-web\code\iam-web>npm run d ...

  7. netcore项目使用swagger开发

    首先我创建一个netcore项目,我使用的工具是vs2019 这里需要注意的是,看情况选择是否开启身份验证,一般是没有需求的,这里因为我是测试使用所以需要取消勾兑为https配置,并且我没有启用doc ...

  8. Simple GB28181 System

    I. Deployment  / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server and media ...

  9. STS插件创建springboot项目,pom第一行报unkown错误

    Description    Resource    Path    Location    TypeUnknown    pom.xml    /amq-provider    line 1     ...

  10. 【转】WebRTC之RTCP

    转自:https://blog.csdn.net/momo0853/article/details/88051312#RTPFBTransport_layer_FB_messagesNACKTrans ...