标签:amp math operator its opera 最大化 来源 isp blog
http://poj.org/problem?id=3111
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int maxn = 100005;
const int INF = 1000006;
struct node {
int v,w,id;
double y;
bool operator < (const node& x) const {
return y>x.y;
}
} jew[maxn];
int n,k;
bool check(double x) {
for(int i=1;i<=n;++i) jew[i].y=jew[i].v-jew[i].w*x;
sort(jew+1,jew+1+n);
double sum=0;
for(int i=1;i<=k;++i) sum+=jew[i].y;
return sum>=0;
}
int main() {
scanf("%d %d",&n,&k);
for(int i=1;i<=n;++i) {
scanf("%d %d",&jew[i].v,&jew[i].w);
jew[i].id=i;
}
double l=0,r=INF;
for(int i=0;i<100;++i) {
double mid = (l+r)/2;
if(check(mid)) l=mid;
else r=mid;
}
for(int i=1;i<=k;++i) {
if(i==1) printf("%d",jew[i].id);
else printf(" %d",jew[i].id);
}
printf("\n");
return 0;
}
标签:amp math operator its opera 最大化 来源 isp blog
原文地址:http://www.cnblogs.com/lemonbiscuit/p/7923363.html