zoukankan      html  css  js  c++  java
  • 【Codeforces 1118D1】Coffee and Coursework (Easy version)

    【链接】 我是链接,点我呀:)
    【题意】

    题意

    【题解】

    从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中。 a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分到第一天。 这样能保证优先让大的数字能够无损失地加进去。 从而尽可能快的凑够m天

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 100;
    
    int n,m;
    int a[N+10];
    vector<int> v[N+10];
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        cin >> n >> m;
        for (int i = 1;i <= n;i++){
            cin >> a[i];
        }
        sort(a+1,a+1+n);
        reverse(a+1,a+1+n);
        for (int day = 1;day <= n;day++){
            int cur = 1;
            for (int j = 1;j <= day;j++) v[j].clear();
            for (int j = 1;j <= n;j++){
                int len = v[cur].size();
                if (len>0 && a[j]-len<=0){
                    break;
                }
                v[cur].push_back(a[j]);
                cur++;
                if (cur>day) cur = 1;
            }
            int total = 0;
            for (int j = 1;j <= day;j++){
                int len = v[j].size();
                for (int l = 0;l < len;l++){
                    int x = v[j][l];
                    x-=l;
                    total+=x;
                }
            }
            if (total>=m){
                cout<<day<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;
    	return 0;
    }
    
  • 相关阅读:
    格式化你的git message
    git merge
    Git远程操作详解
    Limit
    EmailService
    RequestContextHolder getHttpServletRequest
    spring boot GlobalExceptionHandler @RestControllerAdvice @ExceptionHandler
    redis 的雪崩和穿透?
    FileUtil
    getWeekDay TimeUtil
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10600221.html
Copyright © 2011-2022 走看看