码迷,mamicode.com
首页 > 其他好文 > 详细

【BZOJ1007】【HNOI2008】水平可见直线

时间:2015-06-18 22:19:57      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:bzoj1007   hnoi2008   水平可见直线   计算几何   

链接:

#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;
}

【BZOJ1007】【HNOI2008】水平可见直线

标签:bzoj1007   hnoi2008   水平可见直线   计算几何   

原文地址:http://blog.csdn.net/vmurder/article/details/46551367

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!