zoukankan      html  css  js  c++  java
  • 【BZOJ】 1007: [HNOI2008]水平可见直线(凸壳)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1007

    一开始我贪心的写了下,当然全wa了。。

    这题看了题解感觉很简单。

    首先什么情况才能看到呢?

    wobuzhidao。

    我画图才看出门道的。。

    当前直线与相对他斜率次大和次次大的2条直线时,如果与次大的(或者次次大)的交点在次大与次次大的交点左边,那么次大的直线一定被覆盖掉了!

    画图自己看!(其实也就是这三个点形成一个凸包,然后上凸包的边所在直线一定看得到,下凸包一定被覆盖!)

    所以我们用一个栈来维护这3者的关系

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << #x << " = " << x << endl
    #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
    
    const int N=50005;
    struct Line { double a, b; int id; }l[N];
    const bool cmp(const Line &a, const Line &b) { return (abs(a.a-b.a)<=1e-10) ? a.b<b.b : a.a<b.a; }
    int n, vis[N], top, st[N];
    
    inline double crossx(const int &x, const int &y) { return (double)(l[x].b-l[y].b)/(l[y].a-l[x].a); }
    inline void insert(const int &x) {
    	while(top) {
    		if(abs(l[st[top]].a-l[x].a)<=1e-10) --top;
    		else if(top>1 && crossx(x, st[top])<=crossx(st[top], st[top-1])) --top;
    		else break;
    	}
    	st[++top]=x;
    }
    int main() {
    	read(n);
    	for1(i, 1, n) { read(l[i].a); read(l[i].b); l[i].id=i; }
    	sort(l+1, l+1+n, cmp);
    	for1(i, 1, n) insert(i);
    	for1(i, 1, top) vis[l[st[i]].id]=1;
    	for1(i, 1, n) if(vis[i]) printf("%d ", i);
    	return 0;
    }
    

    Description

    Input

    第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi

    Output

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

    Sample Input

    3
    -1 0
    1 0
    0 0

    Sample Output

    1 2

    HINT

    Source

  • 相关阅读:
    divide two numbers using + opertor
    广播
    如何计算传递进来的参数个数 ?
    如何在脚本中使用参数 ?
    shell脚本中“$?”标记的用途是什么?
    JAVA BigDecimal的相加
    【推荐】腾讯android镜像(做Android开发的得好好利用下这个网站,国内的大公司还是可以滴……)
    AndroidDevTools简介
    Android SDK代理服务器解决国内不能更新下载问题
    SugarCRM 插件介绍
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/3938137.html
Copyright © 2011-2022 走看看