码迷,mamicode.com
首页 > 其他好文 > 详细

水水就好

时间:2015-04-15 19:39:16      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:acm

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;
#define maxn 10000
#define eps 1e-8

struct
{
   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 2
2 2
5 3
2 1
*/

水水就好

标签:acm

原文地址:http://blog.csdn.net/dojintian/article/details/45062529

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!