POJ-2976 dropping tests && 0/1 score Planning

Source: Internet
Author: User

POJ-2976 dropping tests

You have \ (n\) exam results, the definition of the Test average score of \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} b_{i}}\]
You may consider giving up \ (k\) grades, asking for the maximum average score * 100

Episode: Being precision Kacheng sheep and sheep

0/1 Fractional Planning\ (from\)Life Mentor Solution

01 Score Planning (not very) bare topic, in each \ (check\) , select the larger \ (num-k + 1\) times to

Code
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <  algorithm> #include <climits> #define LL long longusing namespace std;double RD () {double out = 0,flag = 1;char C    = GetChar ();    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') ' flag = -1;c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') {off = out * + C-' 0 '; c = GetChar ();}    return flag * out;         }const int maxn = 2019;int num, k;double A[MAXN], B[maxn],c[maxn];bool check (double K) {for (int i = 1;i <= num;i++) {        C[i] = A[i]-b[i] * k;    } sort (c + 1, C + 1 + num);    Double temp = 0;    for (int i = num;i > k;i--) Temp + = C[i];    if (Temp > 0) return 1;    return 0;    }double Search (double L, double R) {double ans;        while (R-l > 0.000000001) {Double mid = (L + r)/2;        if (check (mid)) ans = Mid, L = mid;        else R = Mid;    } return ans;        }int Main () {while (1) {num = rd (), K = Rd (); if (!num&&!        K) return 0;        for (int i = 1;i <= num;i++) a[i] = RD ();        for (int i = 1;i <= num;i++) b[i] = RD ();        printf ("%.0f\n", * search (0, 1000000019)); }    }

POJ-2976 dropping tests && 0/1 score plan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.