原题传送门:http://poj.org/problem?id=2653
博主的中文题面(数据范围较小):
https://www.luogu.org/problemnew/show/T22901

Pick-up sticks

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.

题目大意

按顺序给出多条线段,后面的线段可覆盖前面的,求在最上面的线段。

题解

这道题数据比较水(因为题目保证在顶端的棍子不超过1000,然而中间结果是可能超过一千的,不过数据很水没有卡),博主O(nm)的算法居然A了。  
只需要按棍子抛出的顺序枚举,将当前在顶端的线段储存在数组中,每次加入新线段时爆扫一遍,如果该线段被新的线段覆盖,就将该线段弹出,(腾出的空间可以装新的线段,扫描的时候记一下就好了,不加这个优化会T。当然,你也可以加链表)没有可覆盖的线段的话就放在队位,枚举完排一边序即可AC(输出格式稍微注意一下)。

代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#define db double
using namespace std;
const int M=1e5+10;
const db eps=1e-8;
int n,top,tot;
struct pt{db x,y;};
struct li{pt x1,x2;int n;};
bool operator < (const li &a,const li &b){return a.n<b.n;}
li line[M];
li ans[M];
void in()
{pt a,b;for(int i=1;i<=n;++i){scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);line[i].x1=a;line[i].x2=b;line[i].n=i;}
}
int sig(db x){return (x>eps)-(x<-eps);}
db operator * (pt a,pt b){return a.x*b.y-a.y*b.x;}
pt operator - (pt a,pt b){pt hh;hh.x=a.x-b.x;hh.y=a.y-b.y;return hh;}
db cross(pt a,pt b,pt c)
{return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
bool test(li x,li y)
{int s1,s2,s3,s4;s1=sig(cross(x.x1,y.x1,y.x2));s2=sig(cross(x.x2,y.x1,y.x2));s3=sig(cross(y.x1,x.x1,x.x2));s4=sig(cross(y.x2,x.x1,x.x2));if((s1^s2)==-2&&(s3^s4)==-2) return 0;return 1;
}
void check(li x)
{int pos=-1;for(int i=1;i<=top;++i){if(ans[i].n>=1e9){pos=i;continue;}if(!test(x,ans[i])){--tot;ans[i].n=1e9;}}++tot;if(pos>0) ans[pos]=x;else ans[++top]=x;
}
void ac()
{top=0;tot=1;ans[++top]=line[1];for(int i=2;i<=n;++i)check(line[i]);sort(ans+1,ans+1+top);printf("Top sticks: ");for(int i=1;i<tot;++i)printf("%d, ",ans[i].n);printf("%d.\n",ans[tot].n);memset(ans,0,sizeof(ans));memset(line,0,sizeof(line));
}
int main()
{while(scanf("%d",&n)==1&&n){in(),ac();}return 0;
}

POJ2653 Pick-up sticks相关推荐

  1. DP(01背包) UESTC 1218 Pick The Sticks (15CCPC C)

    题目传送门 题意:长度为L的金条,将n根金棍尽可能放上去,要求重心在L上,使得价值最大,最多有两条可以长度折半的放上去. 分析:首先长度可能为奇数,先*2.然后除了两条特殊的金棍就是01背包,所以dp ...

  2. uestc oj 1218 Pick The Sticks (01背包变形)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...

  3. HDU5543 Pick The Sticks [背包dp变形]

    题意: 用一个线性的箱子放黄金, 金条可以露出来一般而不掉出来.问给定金条长度,价值,箱子长度,问最多能放多少金条. 思路: 如果没有可以露出来的限制,那么为裸的01背包问题.现在多了这个限制,是在状 ...

  4. Hadoop SequenceFile数据结构介绍及读写

    在一些应用中,我们需要一种特殊的数据结构来存储数据,并进行读取,这里就分析下为什么用SequenceFile格式文件. Hadoop SequenceFile Hadoop提供的SequenceFil ...

  5. centos nfs java_CentOS下安装配置NFS并通过Java进行文件上传下载

    1:安装NFS (1)安装 yum install nfs-utils rpcbind (2)启动rpcbind服务 systemctl restart rpcbind.service 查看服务状态 ...

  6. Properties类详细解析

    java.util 类 Properties java.lang.Objectjava.util.Dictionary<K,V>java.util.Hashtable<Object, ...

  7. Hadoop入门(五)IO操作

    一.HadoopIO操作意义 Hadoop自带一套用于I/O的原子性的操作 (不会被线程调度机制打断,一直到结束,中间不会有任何context switch) 特点 基于保障海量数据集的完整性和压缩性 ...

  8. java-- properties总结

    转载自  java-- properties总结 篇章一:Loading Properties from XML XML 属性文档具有以下 DOCTYPE 声明: <!DOCTYPE prope ...

  9. java mapfile_基于文件的数据结构:关于MapFile

    MapFile是已经排过序的SequenceFile,它有索引,所以可以按键查找 1.MapFile的写操作 MapFile的写操作类似于SequenceFile的写操作.新建一个MapFile.Wr ...

  10. Properties 类的使用

    Properties 类已不是新东西了,它在 Java 编程的早期就有了,并且几乎没有什么变化.J2SE 的 Tiger 版本增强了这个类,不仅可以用它在单独一行中指定用等号分隔的多个键-值对,还可以 ...

最新文章

  1. python matplotlib模块——绘制三维图形、三维数据散点图
  2. 测试dali协议的软件,基于DALI协议的数字照明控制软件的研发
  3. upload总结及一般处理思路步骤
  4. Android 核心分析之十二Android GEWS窗口管理之基本架构原理
  5. linux命令文件加密软件,Linux系统下如何加密文件,简单实用的文件管理器GnuPG
  6. linux rootfs编译进内核,九鼎x6818开发板笔记:uboot、kernel、rootfs编译和烧写
  7. C#实现网页加载后将页面截取成长图片 | Playwright版
  8. NC107617 poj3020 Antenna Placement
  9. 【渝粤题库】国家开放大学2021春3979会计学概论题目
  10. java - 判断任意一天是这年的第几天
  11. ansys18安装以后打不开_【偷偷告诉你】在微信里直接安装apk.1
  12. [转]使用Visual C#制作可伸缩个性化窗体
  13. 韩国财长:韩国将按计划推进加密货币征税
  14. 卷积神经网络原理解析
  15. 射频信号处理知识点点滴滴
  16. [bzoj4540][莫队算法]序列
  17. 华硕重装后进入bios_华硕笔记本重装系统后直接进入bios,怎么处理
  18. 用python画钢铁侠_Matplotlib绘制漫威英雄战力图,带你飞起来!
  19. Github-谷歌插件gitzip(加速器-不用再忍受几十kb/s的煎熬了)
  20. wxWidgets(1) :mac下搭建wxWidgets 3.0 环境

热门文章

  1. 使用MEAT在iOS设备上采集取证信息
  2. java map格式化_字符串模板格式化输出map 值
  3. 手机点餐系统概述_自助点餐、自助收银......在餐饮行业有哪些智慧化场景?
  4. ssh服务器安装测试
  5. 创新课程管理系统——测试心得
  6. android 控件获取 获取焦点
  7. (12.05)Java小知识!
  8. POJ 3862 POJ 3528 HDU 3662 HDU 4273 三维凸包问题解决模板
  9. 自动布局之autoresizingMask
  10. c3p0 mysql 连接池配置文件_使用XML配置c3p0数据库连接池