zoukankan      html  css  js  c++  java
  • [CF808C] Tea Party(贪心)

    题目链接:http://codeforces.com/contest/808/problem/C

    题意:n个茶杯,每个茶杯有容量。现在给一壶茶,总量为w。希望倒茶满足条件:每杯茶要超过容量的一半,并且w被倒光,茶杯内的茶水为整数,容量大的杯子内的茶不允许比容量小的杯子内的茶水少。

    特判不满足情况,然后将茶水给每一杯倒至一半以上。然后按照容量从大到小每次倒一个单位,直到倒完为止。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 typedef long long LL;
     5 const int maxn = 200200;
     6 int n, w, b[maxn];
     7 pair<int,int> a[maxn];
     8 
     9 int main() {
    10     // freopen("in", "r", stdin);
    11     while(~scanf("%d%d",&n,&w)) {
    12         for(int i = 1; i <= n; i++) {
    13             scanf("%d", &a[i].first);
    14             a[i].second = i;
    15         }
    16         sort(a+1, a+n+1);
    17         int tot = 0;
    18         for(int i = 1; i <= n; i++) {
    19             b[a[i].second] = (int)ceil(a[i].first / 2.0);
    20             tot += b[a[i].second];
    21         }
    22         if(tot > w) {
    23             puts("-1");
    24             continue;
    25         }
    26         w -= tot;
    27         while(w) {
    28             for(int id = n; id >= 1; id--) {
    29                 if(!w) break;
    30                 if(b[a[id].second] < a[id].first) {
    31                     b[a[id].second]++; w--;
    32                 }
    33             }
    34         }
    35         for(int i = 1; i <= n; i++) {
    36             printf("%d%c", b[i], i==n?'
    ':' ');
    37         }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    HDU 5710 digit sum
    Fibonacci Tree HDU
    2016CCPC东北赛补题
    紫书水题
    20180415校赛
    随心所欲小游戏
    Alpha版本测试报告
    第四天作业
    第二天作业
    第一天作业
  • 原文地址:https://www.cnblogs.com/kirai/p/6861840.html
Copyright © 2011-2022 走看看