1007: [HNOI2008]水平可见直线
2013-12-04 18:50
267 查看
先对a排序,a相等的话就对b排序;
维护一个栈,每次取栈的头两个,和当前的直线相比较;
如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止;
代码:
View Code
维护一个栈,每次取栈的头两个,和当前的直线相比较;
如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止;
代码:
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 500005 using namespace std; int st[maxn],top; int num[maxn]; struct line { int a,b; int id; bool operator<(const line &t)const { if(a==t.a)return b>t.b; else return a<t.a; } } l[maxn]; bool check(int x,int y,int z) { double x1=((double)(l[y].b-l[x].b))/((double)(l[x].a-l[y].a)); double x2=((double)(l[z].b-l[x].b))/((double)(l[x].a-l[z].a)); if(x1<x2||(x1-x2)<0.00001)return 1; return 0; } int main() { int n; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d%d",&l[i].a,&l[i].b); l[i].id=i; } sort(l+1,l+n+1); for(int i=1; i<=n; i++) { while(top>1) { if(check(i,st[top-1],st[top-2]))top--; else break; } if(top==0||l[st[top-1]].a!=l[i].a) st[top++]=i; } int cnt=0; for(int i=0; i<top; i++) num[cnt++]=l[st[i]].id; sort(num,num+cnt); for(int i=0; i<cnt; i++) printf("%d ",num[i]); puts(""); return 0; }
View Code
相关文章推荐
- unix 网路编程(卷一)第一个程序编译过程unix网络编程 第一个例子 connect error: Connection refused
- voilate详解
- IrfanView 4.36 中文版发布了
- 韩老师讲SQL2005数据库开发 环境准备代码
- 移动webapp注意问题
- hive函数 -- acos
- Android利用LocalSocket实现Java端进程与C端进程之间的IPC
- 我会每天都来签到的哦
- 数据库——(如何修改数据库的名字)
- OpenCV学习笔记(9)利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面
- 移植一个cocos2d-x游戏
- 复习下修饰符
- [对话CTO]甲骨文熊光樑:全球研发模式开发出接地气产品
- 数组的全排列组合算法
- 黑马程序员---多线程
- Python‘ssl.match_hostname()’函数SSL证书验证安全绕过漏洞
- 学习计算机知识,对以后会有很大的帮助的
- 今天我来注册,很开心哦
- 这之间到底有多少闰年
- 常见加密算法简介