首页 技术 正文
技术 2022年11月14日
0 收藏 658 点赞 2,253 浏览 1101 个字

1007: [HNOI2008]水平可见直线

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 5120  Solved: 1899
[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

Source

【思路】

单调栈维护下凸包。

【代码】

 #include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
using namespace std; const int N = +;
const double eps = 1e-; struct Line {
double a,b; int r;
bool operator < (const Line& rhs) const {
if(fabs(a-rhs.a)<eps) return b<rhs.b;
else return a<rhs.a;
}
}L[N],S[N]; double cross(Line x1,Line x2) {
return (x2.b-x1.b)/(x1.a-x2.a);
} int n,flag[N],top; int main() {
scanf("%d",&n);
FOR(i,,n) {
scanf("%lf%lf",&L[i].a,&L[i].b);
L[i].r=i;
}
sort(L+,L+n+);
FOR(i,,n) {
while(top) {
if(fabs(S[top].a-L[i].a)<eps) top--;
else if(top> && cross(L[i],S[top-])<=cross(S[top],S[top-])) top--;
else break;
}
S[++top]=L[i];
}
FOR(i,,top) flag[S[i].r]=;
FOR(i,,n) if(flag[i])
printf("%d ",i);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905