BZOJ 1007: [HNOI2008]水平可见直线( 计算几何 )
2015-09-23 18:47
537 查看
![](http://images2015.cnblogs.com/blog/723896/201509/723896-20150923183100834-816823662.png)
按A从小到大排序然后用栈解决.
--------------------------------------------------------------------
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 50009; struct L { int A, B, id; inline void Read(int p) { scanf("%d%d", &A, &B); id = p; } bool operator < (const L &o) const { return A < o.A || (A == o.A && B > o.B); }} S[maxn]; int N, sta[maxn], top = 0;bool ans[maxn]; bool check(int a, int b, int c) { return (ll) (S.A - S[c].A) * (S[b].B - S[a].B) >= (ll) (S[c].B - S[b].B) * (S[a].A - S[b].A);} int main() { scanf("%d", &N); for(int i = 0; i < N; i++) S[i].Read(i); sort(S, S + N); sta[top = 0] = 0; for(int i = 1; i < N; i++) { if(S[i].A == S[sta[top]].A) continue; while(top && check(sta[top - 1], sta[top], i)) top--; sta[++top] = i; } memset(ans, 0, sizeof ans); for(; ~top; top--) ans[S[sta[top]].id] = true; for(int i = 0; i < N; i++) if(ans[i]) printf("%d ", i + 1); puts(""); return 0;[b]}--------------------------------------------------------------------
1007: [HNOI2008]水平可见直线
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4676 Solved: 1725
[Submit][Status][Discuss]
Description
在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的.例如,对于直线:
L1:y=x; L2:y=-x; L3:y=0
则L1和L2是可见的,L3是被覆盖的.
给出n条直线,表示成y=Ax+B的形式(|A|,|B|<=500000),且n条直线两两不重合.求出所有可见的直线.
Input
第一行为N(0 < N < 50000),接下来的N行输入Ai,BiOutput
从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格Sample Input
3-1 0
1 0
0 0
Sample Output
1 2HINT
Source
相关文章推荐
- ubuntu apache2 wsgi 部署django
- Hibernate的generator属性
- ZOJ.3437 Very Hard Problem【strtoll函数】 2015/09/23
- intro: what's the problem
- 在做微信第三方的时候遇到的问题、导包问题
- [memcached]部署memcached环境及PHP扩展
- mysqldump备份警告
- 探索Ionic过程中的一些亮点与各种坑整理
- LeetCode(49) Populating Next Right Pointers in Each Node I II
- 数据库存储树形结构的数据
- 安卓:ActionBar的分离
- quick减少包体
- shell 时间统计脚本
- [shell]php-fpm容易假死,实现自动重启php服务~
- java 容器中排序算法的源码实现分析(京东电话面试)
- 黑马程序员---Java基础---IO流
- 排序值冒泡排序的详解
- linux下添加PATH环境变量
- 程序员的业余项目
- Linux 命令 - traceroute: 数据报传输路径追踪