【BZOJ1007】【HNOI2008】水平可见直线
2015-06-18 19:14
387 查看
链接:
#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 ; 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 ,L ; 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 ,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; }
相关文章推荐
- Heartbeat配置
- U-Boot移植_DDR3移植
- Web采矿技术
- oracle sql 执行计划分析
- StoryBoard下ScrollView如何添加约束
- 小小的心得感悟
- USB OTG简要
- 日语学习之沪江N3基础 20150618 -6
- JAAVA选择排序
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue )
- 一个有意思的题-小猴子下落
- osgearth中文乱码问题
- 阅读《构建之法》第13-17章
- How to set the default input focus on a field in an HTML web form
- 【Unity3d】在Unity3d中调用外部程序及批处理文件,写自动化编译脚本需要注意的地方
- Unicode汉字编码表
- dedecms全版本设计缺陷导致验证码绕过(可用于爆破等)
- LeetCode —— Invert Binary Tree
- 4.Lua面向对象概念
- nagios 监控 mongodb 解决nagios界面显示null 问题