1007: [HNOI2008]水平可见直线

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 7940  Solved: 3030
[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,Bi

Output

  从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格

Sample Input

3
-1 0
1 0
0 0

Sample Output

1 2

HINT

析:先把所有的直线按斜率从小到大,按截距从大到小排序,然后维护一个栈,如果一个栈里只有一个元素,并且下一条线斜率不和本条相同,直接进栈,否则就要进行判断,设栈顶的直线与要判的直线 x 轴交点为x1,栈最上面两条直线交点为 x2,如果 x1<=x2,那么就删除栈顶的直线,它不可能被看到,依次重复直接条件不成立。栈里的直线就是答案。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-3;
const int maxn = 1e5 + 10;
const int maxm = 3e5 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Line{
int id, k, b;
bool operator < (const Line &l) const{
return k < l.k || k == l.k && b > l.b;
}
};
Line a[maxn];
stack<Line> st; double crossX(const Line &lhs, const Line &rhs){
return (rhs.b - lhs.b) * 1. / (lhs.k - rhs.k);
} int main(){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
a[i].id = i;
scanf("%d %d", &a[i].k, &a[i].b);
}
sort(a, a + n);
st.push(a[0]);
for(int i = 1; i < n; ++i){
if(a[i].k == st.top().k) continue;
if(st.sz == 1){ st.push(a[i]); continue; }
while(st.sz != 1){
Line l = st.top(); st.pop();
double x1 = crossX(l, a[i]);
double x2 = crossX(l, st.top());
if(x1 > x2){ st.push(l); break; }
}
st.push(a[i]);
}
vector<int> ans;
while(!st.empty()){
ans.push_back(st.top().id); st.pop();
}
sort(ans.begin(), ans.end());
for(int i = 0; i < ans.sz; ++i) printf("%d ", ans[i]+1);
printf("\n");
return 0;
}

  

BZOJ 1007 [HNOI2008]水平可见直线 (栈)的更多相关文章

  1. BZOJ 1007: [HNOI2008]水平可见直线 栈/计算几何

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec  Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline ...

  2. bzoj 1007 [HNOI2008]水平可见直线(单调栈)

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5120  Solved: 1899[Submit][Sta ...

  3. BZOJ 1007 [HNOI2008]水平可见直线

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4453  Solved: 1636[Submit][Sta ...

  4. 2018.07.03 BZOJ 1007: [HNOI2008]水平可见直线(简单计算几何)

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB Description 在xoy直角坐标平面上有n条直线L1,L2,-Ln, ...

  5. BZOJ 1007: [HNOI2008]水平可见直线 平面直线

    1007: [HNOI2008]水平可见直线 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则 ...

  6. BZOJ.1007.[HNOI2008]水平可见直线(凸壳 单调栈)

    题目链接 可以看出我们是要维护一个下凸壳. 先对斜率从小到大排序.斜率最大.最小的直线是一定会保留的,因为这是凸壳最边上的两段. 维护一个单调栈,栈中为当前可见直线(按照斜率排序). 当加入一条直线l ...

  7. bzoj 1007 : [HNOI2008]水平可见直线 计算几何

    题目链接 给出n条直线, 问从y轴上方向下看, 能看到哪些直线, 输出这些直线的编号. 首先我们按斜率排序, 然后依次加入一个栈里面, 如果刚加入的直线, 和之前的那条直线斜率相等, 那么显然之前的会 ...

  8. bzoj 1007: [HNOI2008]水平可见直线 半平面交

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=1007; 题解 其实就是求每条直线的上半部分的交 所以做裸半平面交即可 #include ...

  9. bzoj 1007: [HNOI2008]水平可见直线【半平面交】

    其实并不算标准半平面交?但是思路差不多 先按照斜率排序,然后用栈维护凸壳,每遇到重斜率或a[i],s[top-1]交点的x轴在s[top],s[top-1]交点左侧,则说明s[top]被a[i],s[ ...

随机推荐

  1. vue基础——条件渲染

    一.v-if 1.1.v-if,v-else 在字符串模板中,比如Handlebars,我们得像这样写一个条件块: HTML <!-- Handlebars 模板 --> {{#if ok ...

  2. Mysql生成索引的方式

    1.选择索引的数据类型 MySQL支持很多数据类型,选择合适的数据类型存储数据对性能有很大的影响.通常来说,可以遵循以下一些指导原则: (1)越小的数据类型通常更好:越小的数据类型通常在磁盘.内存和C ...

  3. SQL 2008维护计划不执行的问题

    平台环境; 先是装了WINDOWS 2008,没有升级到AD,再安装了sql2008后再升级了AD. 现在SQL建了几个数据库备份计划,但都提示下面的信息: 日期  2010-4-15 9:36:00 ...

  4. lua 中的点、冒号与self

    [lua 中的点.冒号与self] lua编程中,经常遇到函数的定义和调用,有时候用点号调用,有时候用冒号调用. girl = {money = 200} function girl.goToMark ...

  5. org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"", local:"mixornot")。

    三月 09, 2018 3:09:14 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging警告: Interceptor fo ...

  6. CSS的浮动(float)

    问题:在练习过程中,发现div1浮动后,它下面的div被覆盖住了. 解决方案:清除该div1的浮动. 关于CSS的浮动 1.div是块级元素,独占一行 2.浮动可以理解为让某个div元素脱离标准流,漂 ...

  7. HTML5 historyState pushState、replaceState

    DOM中的window对象通过window.history方法提供了对浏览器历史记录的读取,让你可以在用户的访问记录中前进和后退. 从HTML5开始,我们可以开始操作这个历史记录堆栈. 1.Histo ...

  8. 利用python计算windows全盘文件md5值的脚本

    import hashlib import os import time import configparser import uuid def test_file_md5(file_path): t ...

  9. js variable 变量

    局部作用域 由于JavaScript的变量作用域实际上是函数内部,我们在for循环等语句块中是无法定义具有局部作用域的变量的: 'use strict'; function foo() { for ( ...

  10. php Pthread 多线程 (二) Worker和Threaded

    <?php //Worker是具有持久化上下文(执行环境)的线程对象 //Worker对象start()后,会执行run()方法,run()方法执行完毕,线程也不会消亡 class MySqlW ...