首页 > 其他 > 详细

水水就好

时间:2015-04-15 19:37:55      阅读:124      评论:0      收藏:0      [点我收藏+]
#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
*/

水水就好

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!