zoukankan      html  css  js  c++  java
  • [CF846B]Math Show题解

    暴力一下就好啦!
    枚举一下一共做多少次任务,剩下的时间将子任务排序,从头开始能取多少取多少就行了。

    贴个代码

    #include <cstdio>
    #include <algorithm>
    #define ll long long
    
    using namespace std;
    
    inline ll read(){
        ll x = 0; int zf = 1; char ch = ' ';
        while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
        if (ch == '-') zf = -1, ch = getchar();
        while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
    }
    
    ll cost[50];
    
    ll tot = 0;
    
    int main(){
        int n = read(), k = read(), M = read();
        for (int i = 1; i <= k; ++i)
            cost[i] = read(), tot += cost[i];
        sort(cost + 1, cost + k + 1);
        long long cur, ans = 0, left;
        for (int i = 0; i <= n; ++i){
            if (M - tot * i < 0)
                break;
            left = M - tot * i;
            cur = i * (k + 1);
            for (int j = 1; j <= k; ++j){
                for (int k = 1; k <= (n - i); ++k){
                    if (left - cost[j] >= 0)
                        left -= cost[j], ++cur;
                    else
                        break;
                }
            }
            if (cur > ans)  
                ans = cur;
        }
        printf("%lld", ans);
        return 0;
    }
    
  • 相关阅读:
    c语言中的数据变量类型,大小
    表达式* ptr ++和++ * ptr是否相同?
    再论i++ ++i
    Chapter 1 First Sight——2
    如何修改博客样式
    PAT1011
    Chapter 1 First Sight——1
    Preface
    L11,one good turn deserves another
    PAT1010
  • 原文地址:https://www.cnblogs.com/linzhengmin/p/10861591.html
Copyright © 2011-2022 走看看