poj 3111 K Best
来源:互联网 发布:淘宝快捷支付怎么开通 编辑:程序博客网 时间:2024/05/29 10:11
本来是条很简单的题,可是细节好多,不会处理,神烦。(最大化平均值)
1.精度问题,需要设置到1e-6内
2.储存问题,把a外置就不行了,,,why??
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>using namespace std;const int maxn=1000000+10;const int INF=1e7+1;struct node{int t;double sum;}s[maxn];int a[maxn],v[maxn],w[maxn],n,k;int cmp(node l1,node l2){return l1.sum>l2.sum;}bool C(double d){ for(int i=1;i<=n;i++) { s[i].t=i; s[i].sum=v[i]-d*w[i];}sort(s+1,s+n+1,cmp);double res=0;for(int i=1;i<=k;i++) //不能把a[i]和res分开写,细节好多,好烦 {res+=s[i].sum;a[i]=s[i].t; } return res>=0;} void solve(){double lb=0,ub=INF;while(ub-lb>1e-6) //精度要求好高 {double mid=(lb+ub)/2;if(C(mid)) lb=mid;else ub=mid;}for(int i=1;i<=k;i++)cout<<a[i]<<" ";cout<<endl;}int main(){ while(~scanf("%d%d",&n,&k)){ for(int i=1;i<=n;i++) scanf("%d%d",&v[i],&w[i]); solve();} }
0 0
- POJ 3111 K Best
- poj 3111 K Best
- POJ-3111K Best
- poj 3111 K Best
- POJ 3111K Best
- POJ 3111 K Best 笔记
- poj 3111 K Best 二分
- POJ 3111 K Best 最大化平均值
- POJ 3111 - K Best(二分搜索)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best <最大化平均,二分>
- poj 3111 K Best(二分)
- POJ 3111 K Best 【二分:最大化平均值】
- POJ 3111 K Best 二分 最大化平均值
- POJ 3111:K Best(思维+二分)
- POJ 3111 K Best 01分治
- K Best POJ
- AT89S52串口测试程序
- 分库
- javascript心得随记
- 此博客主要用来记录自己从他人学习到的东西
- 输入一个链表,输出该链表中倒数第k个结点。
- poj 3111 K Best
- [LeetCode]Generalized Abbreviation
- android 中遥控器键值的添加和修改
- Android异常java.lang.IllegalStateException: The specified child already has a parent.
- 《从零开始学Swift》学习笔记(Day 63)——Cocoa Touch设计模式及应用之单例模式
- ES2015 - Array (4)
- mysql审计插件(运维不在背锅)
- C语言单链表——之常见面试题目2
- 三种多线程简介及使用方法