CSU-ACM2017暑假集训比赛1 TD POJ3111
来源:互联网 发布:百度seo规则 编辑:程序博客网 时间:2024/06/17 15:15
#include<cstdio>#include<cstring>#include<algorithm>#define maxl 100010#define inf 2000000001#define eps 1e-7using namespace std;int n,k;double ans;double v[maxl],w[maxl];struct node{double num;int pos;} a[maxl];void prework(){scanf("%d%d",&n,&k);for(int i=1;i<=n;i++)scanf("%lf%lf",&v[i],&w[i]);}bool cmp(const node &x,const node &y){return x.num>y.num;}bool jug(double x){for(int i=1;i<=n;i++)a[i].num=v[i]-w[i]*x,a[i].pos=i;sort(a+1,a+1+n,cmp);double sum=0;for(int i=1;i<=k;i++)sum+=a[i].num;if(sum>eps)return true;elsereturn false;}void mainwork(){double l=eps,r=inf-eps,mid;while(l+eps<r){mid=(l+r)/2.0;if(jug(mid))l=mid;elser=mid;}ans=l;}void print(){jug(ans);for(int i=1;i<=k;i++)printf("%d ",a[i].pos);}int main(){prework();mainwork();print();return 0;}
Demy has n jewels. Each of her jewels has some value vi and weight wi.
Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1, i2, …, ik} as
.
Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.
选出能使上式最大的k个珠子、
选出vi/wi最大的珠子无法满足vi之和/wi之和最大。于是我们二分这个最大值为x
然后 求一组(vi+vj....)/(wi+wj..)=x,移项得 (vi+vj...)-(wi+wj..)*x=0,而我们要求最大的x,所以只要(vi+vj...)-(wi+wj..)*x >= 0,这个x就是满足的。
阅读全文
0 0
- CSU-ACM2017暑假集训比赛1 TD POJ3111
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 B
- CSU-ACM2017暑假集训比赛1 A
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- R2D2 and Droid Army--CSU-ACM2017暑假集训比赛1
- CSU-ACM2017暑假集训比赛2 C
- CSU-ACM2017暑假集训比赛2 D
- CSU-ACM2017暑假集训比赛2 B
- CSU-ACM2017暑假集训比赛2 A
- CSU-ACM2017暑假集训比赛2 E
- CSU-ACM2017暑假集训比赛2 HDU
- CSU-ACM2017暑假集训比赛2 CodeForces
- CSU-ACM2017暑假集训比赛3D
- CSU-ACM2017暑假集训比赛7 A
- CSU-ACM2017暑假集训比赛7 B
- CSU-ACM2017暑假集训比赛7 C
- Djikstra算法
- jstl 使用备忘
- Monthly Expense
- 杭电oj1013
- LeetCode 453 Minimum Moves to Equal Array Elements
- CSU-ACM2017暑假集训比赛1 TD POJ3111
- POI实现海量数据导出到excel文件
- Xcode配置Python开发环境
- jdk环境的配置(Java编译环境)以及tomcat的安装
- Is Derek lying?
- SSH框架搭建步骤及思路
- hpuoj 【1341】统计奇偶数 【水题】
- pickle, cPickle 模块:序列化 Python 对象
- JS中client/offset/scroll等的宽高解析