• 题面描述

    • 在\(xOy\)直角坐标平面上有\(n\)条直线\(L_1,L_2,...,L_n\),若在\(y\)值为正无穷大处往下看,能见到\(L_i\)的某个子线段,则称\(L_i\)为可见的,否则\(L_i\)为被覆盖的.例如,对于直线:\(L_1:y=x; L_2:y=-x; L_3:y=0\)则\(L_1\)和\(L_2\)是可见的,\(L_3\)是被覆盖的.给出\(n\)条直线,表示成\(y=Ax+B\)的形式\((|A|,|B|\leq 5*10^5)\),且\(n\)条直线两两不重合.求出所有可见的直线.
  • 输入格式
    • 第一行为\(N(0 < N < 50000)\),接下来的\(N\)行输入\(A_i,B_i\)
  • 输出格式
    • 从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格
  • 题解
    • 不难看出该题核心就是对于给定\(n\)条直线,求他们的下凸包
    • 注意有多个\(A_i\)相同的,在压入栈的时候按\(B_i\)从小到大压入,把前面没有被弹出的\(A_x==A_i\)全部弹出
    • 另:前两条直线不能默认直接压进去,因为他们\(A\)可能相等
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN=5e4+5;
const double eps=1e-8;
struct rec{
double a,b;
int id;
} a[MAXN];
int n;
bool cmp(rec a,rec b){ return fabs(a.a-b.a)<eps?a.b<b.b:a.a<b.a; }
int st[MAXN],top;
struct dt{
double x,y;
};
dt dot(int i,int j){
double x=(a[j].b-a[i].b)/(a[i].a-a[j].a);
double y=a[i].a*x+a[i].b;
return (dt){x,y};
}
int ans[MAXN],cnt;
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].a,&a[i].b),a[i].id=i;
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n;i++){
while (top>=1&&fabs(a[st[top]].a-a[i].a)<eps) top--;
while (top>=2&&dot(st[top-1],st[top]).x>=dot(st[top-1],i).x) top--;
st[++top]=i;
}
for (int i=1;i<=top;i++) ans[cnt++]=a[st[i]].id;
sort(ans,ans+cnt);
for (int i=0;i<cnt;i++) printf("%d ",ans[i]);
printf("\n");
return 0;
}

天助自助者

随机推荐

  1. using JSTL

    http://docs.oracle.com/javaee/5/tutorial/doc/bnake.html JSTL(JSP Standard Tag Library)

  2. wp 取消button按下效果

    <Style x:Key="ButtonStyle2" TargetType="Button">            <Setter Pro ...

  3. C#开源网络通信库PESocket的使用

    PESocket PESocket开源项目GitHub地址:点击跳转 基于C#语言实现的高效便捷网络库.支持集成到Unity当中使用. 不用过多了解网络通信内部原理,只需几行简单的代码,便能简捷快速开 ...

  4. [.net 多线程]SpinWait

    <CLR via C#>读书笔记-线程同步(四) 混合线程同步构造简介 之前有用户模式构造和内核模式构造,前者快速,但耗费CPU:后者可以阻塞线程,但耗时.耗资源.因此.NET会有一些混合 ...

  5. 【大数据之数据仓库】HAWQ versus GreenPlum

    谈到GreenPlum,肯定会有同事说HAWQ!是的,在本系列第一篇选型流水记里,也有提到.因为对HAWQ接触有限,没有深入具体了解,所以很多信息都是来自于博文,人云亦云,我把看过的资料简要整理,希望 ...

  6. 「POJ 2699」The Maximum Number of Strong Kings

    题目链接 戳我 \(Describe\) 一场联赛可以表示成一个完全图,点表示参赛选手,任意两点u, v之间有且仅有一条有向边\((u, v)\)或\((v, u)\),表示\(u\)打败\(v\)或 ...

  7. could not read data from '/Users/lelight/Desktop/ViewControllerLife/ViewControllerLife/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file.

    1.Info.plist放置至新文件夹下,路径被修改了,报错. could not read data from '/Users/lelight/Desktop/ViewControllerLife/ ...

  8. linux获取域名地址

    dig live-195887137.cn-north-1.elb.amazonaws.com.cn +short

  9. 738. Monotone Increasing Digits

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  10. Python之路Python作用域、匿名函数、函数式编程、map函数、filter函数、reduce函数

    Python之路Python作用域.匿名函数.函数式编程.map函数.filter函数.reduce函数 一.作用域 return 可以返回任意值例子 def test1(): print(" ...