水水就好

#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
*/

时间: 2024-08-07 10:08:17

水水就好的相关文章

Codeforces 506D Mr. Kitayuta&#39;s Colorful Graph 并查集+水水的分类讨论+水水的离线预处理

首先读入所有的边与询问.将边按颜色分类. 按颜色进行并查集, 若此并查集内的点<= 100,则100*100/2的枚举是否联通. 若此并查集内的点  > 100,则将与这些点相关的所有询问查一遍. 那么时间复杂度为100*100/2*(M/100),或者为M/100*Q. 极限的时候两种方法都在一亿左右了,而且每次还需要在map里搞一搞,还要查询是否联通,不知道为啥没有超时.. #include <algorithm> #include <iostream> #incl

水水的DFS

原题http://acm.hdu.edu.cn/showproblem.php?pid=4536 XCOM Enemy Unknown Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 851    Accepted Submission(s): 257 Problem Description XCOM-Enemy Unknown是一款很好玩

acm hdu p2547 无剑无我{水水水}

无剑无我 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4112    Accepted Submission(s): 2638 Problem Description 北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯.时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从. 值此危急存亡之秋

&amp;&amp;队友最近一周水水

100130 练习5 5 hr ago 15.2 days Private qwerqqq 100093 DP2 16 hr ago 50.2 days Private qwerqqq 100092 DP 16 hr ago 50.2 days Private qwerqqq 100066 练习4.2 1 days ago 15.2 days Private qwerqqq 100062 练习(4) 1 days ago 15.2 days Private qwerqqq 100053 练习 4

POJ2387 水水最短路

迪杰斯特拉哦,很挫哦 A - Til the Cows Come Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2387 Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possib

hd1496----&gt;这道题是水水的数论吗?

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1496 题意: Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.It is consider a solution a system ( x1,x

【BZOJ】初级水题列表——献给那些想要进军BZOJ的OIers(自用,怕荒废了最后的六月考试月,刷刷水题,水水更健康)

BZOJ初级水题列表——献给那些想要进军BZOJ的OIers 代码长度解释一切! 注:以下代码描述均为C++ RunID User Problem Result Memory Time Code_Length 695765 Eolv 1000 Accepted 804 kb 0 ms 118 B 739478 Eolv 2463 Accepted 804 kb 0 ms 134 B 696662 Eolv 1968 Accepted 1272 kb 48 ms 137 B 739546 Eolv

51Nod 1002 数字三角形 Label:水水水 &amp;&amp; 非学习区警告

一个高度为N的由正整数组成的三角形,从上走到下,求经过的数字和的最大值. 每次只能走到下一层相邻的数上,例如从第3层的6向下走,只能走到第4层的2或9上. 5 8 4 3 6 9 7 2 9 5 例子中的最优方案是:5 + 8 + 6 + 9 = 28 Input 第1行:N,N为数塔的高度.(2 <= N <= 500) 第2 - N + 1行:每行包括1层数塔的数字,第2行1个数,第3行2个数......第k+1行k个数.数与数之间用空格分隔(0 <= A[i] <= 10^5

KMP 水水

#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespace std; #define maxn 400000 + 10 int len, next[maxn], cnt = 0; int L; string s1, s; void getnext() { int i = 0; int

最大字段和 51nod 1049 水水水水水水水水水水水水

N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的连续子段和的最大值.当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,-2,和最大的子段为:11,-4,13.和为20. Input 第1行:整数序列的长度N(2 <= N <= 50000) 第2 - N + 1行:N个整数(-10^9 <= A[i] <= 10^9) Output 输出最大子段和. Input示例 6 -2 11 -4 13 -5 -