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. 一些输出、处理细节&注意点

    https://blog.csdn.net/qq_41071646/article/details/79953476 输出百分比的时候,结果需要加上一个EPS(1e-6)四舍五入保证精度. 卡精度—— ...

  2. TensorFlow学习笔记9-深度模型的优化

    深度模型的优化 回顾概念: 代价函数时训练集上损失函数的平均: \[J(\theta)=E_{(x,y)\sim \hat{p}_{data}}L(f(x;\theta),y) \tag{1}\] 引 ...

  3. 20191103 《Spring5高级编程》笔记-第4章

    第4章 详述Spring配置和Spring Boot 4.2 管理bean生命周期 通常,有两个生命周期事件与bean特别相关:post-initialization和pre-destruction. ...

  4. Django密码错误报错提醒

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOwAAAIBCAYAAABKllNhAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw

  5. pycharm中的Terminal 中无法使用git的问题

    1.先找到git的安装路径,建议使用Everything工具 2.打开pycharm中的setting > tools > Terminal 3.把git的安装路径加上启动文件 bash. ...

  6. JAVA10以上版本 搜索不到 dt.jar和tools.jar

    从jdk-9之后就已经没有tools.jar和dt.jar了,也不需要在classpath里面配置这些jar了,配置可参考:JAVA_HOME=jdk安装路径JRE_HOME=jre安装路径PATH= ...

  7. D-query SPOJ 树状数组+离线

    D-query SPOJ 树状数组+离线/莫队算法 题意 有一串正数,求一定区间中有多少个不同的数 解题思路--树状数组 说明一下,树状数组开始全部是零. 首先,我们存下所有需要查询的区间,然后根据右 ...

  8. AcWing 154. 滑动窗口(模板)

    (https://www.acwing.com/problem/content/156/) 给定一个大小为n≤106n≤106的数组. 有一个大小为k的滑动窗口,它从数组的最左边移动到最右边. 您只能 ...

  9. asp.net中的<% %>,<%= %>,<%# %><%$ %>的使用

    原文:https://www.cnblogs.com/Hackerman/p/3857630.html 首先我们来看一下<% %>的使用 在aspx的页面中只能使用服务器控件和一般的控件, ...

  10. javascript事件触发器fireEvent和dispatchEvent

    javascript事件触发器fireEvent和dispatchEvent   事件触发器就是用来触发某个元素下的某个事件,IE下fireEvent方法,高级浏览器(chrome,firefox等) ...