zoukankan      html  css  js  c++  java
  • POJ 2976

    Dropping tests
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 5459   Accepted: 1889

    Description

    In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be

    .

    Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores.

    Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is . However, if you drop the third test, your cumulative average becomes .

    Input

    The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for all i. The third line contains n positive integers indicating bi for all i. It is guaranteed that 0 ≤ ai ≤ bi ≤ 1, 000, 000, 000. The end-of-file is marked by a test case with n = k = 0 and should not be processed.

    Output

    For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer.

    Sample Input

    3 1
    5 0 2
    5 1 6
    4 2
    1 2 7 9
    5 6 7 9
    0 0

    Sample Output

    83
    100

    Hint

    To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).

    Source

     
    二分平均值。
     
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <iostream>
     5 
     6 using namespace std;
     7 
     8 #define maxn 1005
     9 #define eps 1e-6
    10 
    11 int n,k;
    12 int a[maxn],b[maxn];
    13 
    14 bool judge(double x) {
    15         double sum = 0;
    16         double f[maxn];
    17         for(int i = 1; i <= n; ++i) {
    18                 f[i] = a[i] - x * b[i];
    19         }
    20 
    21         sort(f + 1,f + n + 1);
    22 
    23         for(int i = n; i >= n - (n - k) + 1; --i) {
    24                 sum += f[i];
    25         }
    26 
    27         return sum >= 0;
    28 
    29 }
    30 
    31 void solve() {
    32         double l = 0,r = 0;
    33 
    34         for(int i = 1; i <= n; ++i) {
    35                 r += a[i];
    36         }
    37 
    38         while(r - l >= eps) {
    39                 double mid = (l + r) / 2;
    40                 if(judge(mid)) l = mid;
    41                 else r = mid;
    42 
    43         }
    44 
    45        // printf(" l = %f
    ",l);
    46 
    47         printf("%d
    ",(int)(100 * r + 0.5));
    48 }
    49 
    50 int main() {
    51        、、 freopen("sw.in","r",stdin);
    52 
    53         while(~scanf("%d%d",&n,&k)) {
    54         if(!n && !k) break;
    55         for(int i = 1; i <= n; ++i) {
    56                 scanf("%d",&a[i]);
    57         }
    58 
    59         for(int i = 1; i <= n; ++i) {
    60                 scanf("%d",&b[i]);
    61         }
    62 
    63         solve();
    64 
    65         }
    66 
    67         return 0;
    68 }
    View Code
  • 相关阅读:
    容器跨主机网络通信学习笔记(以Flannel为例)
    Kubernetes控制器Job和CronJob
    记一次使用Flannel插件排错历程
    Kubernetes控制器Deployment
    Kubernetes如何通过StatefulSet支持有状态应用?
    react18 来了,我 get 到...
    gojs 实用高级用法
    vuecli3 vue2 保留 webpack 支持 vite 成功实践
    calibre 报错 This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 解决
    unable to recognize "*.yaml": no matches for kind "RoleBinding" in version "rbac.authorization.k8s.io/v1beta1"
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3611868.html
Copyright © 2011-2022 走看看