首页 技术 正文
技术 2022年11月15日
0 收藏 508 点赞 4,477 浏览 1763 个字

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

【BZOJ】 1007: [HNOI2008]水平可见直线(凸壳)

Input

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

Output

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

Sample Input

3
-1 0
1 0
0 0

Sample Output

1 2

HINT

Source

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,918
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,444
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,255
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,069
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,701
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,741