[POJ1018]Communication System(贪心)
来源:互联网 发布:php时间月份差 编辑:程序博客网 时间:2024/04/28 17:06
题目描述
传送门
题意:T组数据。每组数据给出一个n,输入n行,第i行
题解
为什么是dp,明明就是个贪心。。。
枚举一个B,然后在所有大于B的里面每一行选一个,让P尽量小。
交上去了之后竟然跑了140+MS,非常不爽。于是各种砍常数优化循环什么的,其实把B排一下序然后动态维护一个Min时间是可以做到
代码
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;#define N 105int T,n,m,cnt,tot;struct hp{int i;double b,p;}d[N*N];bool flag[N];double inf,Min[N],P,ans;void clear(){ n=m=0;cnt=tot=0;P=0; memset(Min,127,sizeof(Min));inf=Min[0]; memset(flag,0,sizeof(flag)); ans=0;}int cmp(hp x,hp y){ return x.b>y.b;}int main(){ scanf("%d",&T); while (T--) { clear(); scanf("%d",&n); for (int i=1;i<=n;++i) { scanf("%d",&m);double x,y; for (int j=1;j<=m;++j) { scanf("%lf%lf",&x,&y);hp now; now.i=i,now.b=x,now.p=y; d[++cnt]=now; } } sort(d+1,d+cnt+1,cmp); for (int i=1;i<=cnt;++i) { hp now=d[i];if (!flag[now.i]) flag[now.i]=true,tot++; if (Min[now.i]==inf) Min[now.i]=now.p,P+=Min[now.i]; else if (now.p<Min[now.i]) P-=Min[now.i],P+=now.p,Min[now.i]=now.p; if (tot!=n) continue; ans=max(ans,now.b/P); } printf("%0.3lf\n",ans); }}
0 0
- [POJ1018]Communication System(贪心)
- POJ1018 Communication System(DP||贪心)
- ZOJ1409 POJ1018 Communication System
- POJ1018--Communication System
- poj1018 - Communication System
- Poj1018 Communication System
- POJ1018 Communication System
- POJ1018 Communication System
- poj1018:Communication System
- poj1018 Communication System
- [DP]poj1018 Communication System
- poj1018 Communication System dp
- poj1018 Communication System
- poj1018 Communication System
- POJ1018 Communication System 动态规划
- poj1018 Communication System (有道翻译完全拯救不了)
- POJ1018:Communication System(枚举+搜索剪枝)
- POJ1018《Communication System》方法:枚举+剪枝
- 关于更改MySQL默认字符编码的问题
- 类成员函数解析
- awk读取文件里面的某个字段
- 清华EMBA课程系列思考之十三(1) -- 企业传播学
- Shellcode
- [POJ1018]Communication System(贪心)
- 前后台数据交互
- Linux 下编译安装OpenCV
- QT应用程序分辨率自适应
- HUD 5092 Seam Carving(递推)
- 19-Samba
- 在android studio 中引用viewpagerindicator的方法
- Java开发中的23种设计模式详解(转)
- Codeforces Round #377 (Div. 2) D. Exams