水水就好

来源:互联网 发布:php简单留言板源码 编辑:程序博客网 时间:2024/05/18 16:13
#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cstdio>using namespace std;#define maxn 10000#define eps 1e-8struct{   int  w, v;}a[maxn];double b[maxn];int n, k;bool cmp(double a, double b){    return a > b;}bool judge(double x){    cout<<x<<endl;    double ans = 0.0;    for(int i=0; i<n; i++)        b[i] = a[i].v - x * a[i].w;    sort(b, b+n, cmp);    for(int i=0; i<n; i++)        cout<<b[i]<<" ";    cout<<endl;    for(int i=0; i<k; i++)        ans += b[i];        return ans >= 0;}void solve(){    double L = 0;    double R = 1000000;    while((R - L) > eps)    {        double mid = (L + R) / 2;        if(judge(mid)) L = mid;        else R = mid;    }    cout<<L<<endl;}int main(){    while(~scanf("%d%d", &n, &k))    {        for(int i=0; i<n; i++)            {                scanf("%d%d", &a[i].w, &a[i].v);            }            solve();    }    return 0;}/*3 22 25 32 1*/

0 0