bzoj 1007
来源:互联网 发布:thinkphp商城源码下载 编辑:程序博客网 时间:2024/05/16 09:22
这是一个大水题
只需要维护一下凸包就好啦
画一下图发现斜率相同在下面的就看不见啦
斜率不同的手画一下直线交点就好啦
简简单单的栈
#include<bits/stdc++.h>using namespace std;const int MX = 500000 ;const double eps = 1e-8 ;struct node{ double k,b; int id;}e[MX];int n,top,sta[MX],ans[MX];bool com(node a,node b){ return (fabs(a.k-b.k)<eps)?a.b<b.b:a.k<b.k;}double getx(int x){ node a=e[sta[x]],b=e[sta[x-1]]; return (a.b-b.b)/(b.k-a.k);}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf",&e[i].k,&e[i].b),e[i].id=i; sort(e+1,e+n+1,com); sta[++top]=1; for(int i=2;i<=n;i++) { sta[++top]=i; while(fabs(e[i].k-e[sta[top-1]].k)<eps) sta[--top]=i; while(top>2&&(getx(top)-getx(top-1))<eps) sta[--top]=i; } for(int i=1;i<=top;i++) ans[i]=e[sta[i]].id; sort(ans+1,ans+top+1); for(int i=1;i<=top;i++) printf("%d ",ans[i]);}
心得:
1.凸包是非常重要的,还可以用在斜率优化
2.用纸和笔画一下图比较好
阅读全文
0 0
- BZOJ 1007
- bzoj 1007
- bzoj 1007
- BZOJ - 1007 【单调栈】
- [BZOJ ]
- BZOJ****-****
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- bzoj
- bzoj
- 解读zookeeper的配置项
- Mysql 访问控制2 Request Verification
- VC2010项目中附加包含目录
- 到底vuex是什么
- 深入理解Spring MVC
- bzoj 1007
- C++中带默认值参数的函数
- ES 基本使用《二》--组合过滤
- vue 常用Api整理 2
- sl4j日志可在本地写入控制台和文件,在服务器不能写入文件
- 在eclipse里面启动服务器的时候报启动45秒错误
- redis2
- 任学堂说科技:人工智能的火“烧”到了英国,你却还在无动于衷
- vue 常用Api整理 3