链接:
#include <stdio.h>
int main()
{
puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/46551367");
}
题解:
呃。把直线随便排下序,然后扫一遍,类似栈一样删掉被覆盖的直线。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 501000
#define eps 1e-10
#define inf 0x3f3f3f3f
using namespace std;
struct Point
{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
double operator - (const Point &A)const
{return sqrt((x-A.x)*(x-A.x)+(y-A.y)*(y-A.y));}
}P[N];
struct Line
{
int id,k,b;
void read(int i){id=i,scanf("%d%d",&k,&b);}
Line(int i=0,int _k=0,int _b=0):id(i),k(_k),b(_b){}
bool operator < (const Line &A)const
{return k==A.k?b>A.b:k<A.k;}
}line[N],L[N];
bool under(const Point &A,const Line &B)
{return A.y<=B.k*A.x+B.b+eps;}
Point inc(const Line &A,const Line &B)
{
double x=(double)(B.b-A.b)/(A.k-B.k);
return Point(x,x*A.k+A.b);
}
int n,l,r;
int ans[N],cnt;
int main()
{
// freopen("test.in","r",stdin);
int i,j,k;
int a,b,c;
scanf("%d",&n);
for(i=1;i<=n;i++)line[i].read(i);
sort(line+1,line+n+1);
L[l=r=1]=line[1];
for(i=2;i<=n;i++)
{
while(l<r&&under(P[r-1],line[i]))r--;
L[++r]=line[i];
P[r-1]=inc(L[r],L[r-1]);
}
for(i=l;i<=r;i++)ans[++cnt]=L[i].id;
sort(ans+1,ans+cnt+1);
for(i=1;i<=cnt;i++)printf("%d ",ans[i]);
return 0;
}