码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Codeforces Round #835 (Div. 4) F. Quests


    Codeforces Round #835 (Div. 4) F. Quests

    Let’s fix k k k and find the maximum number of coins we can get. Here we can do a greedy solution: at every step, we should always take the most rewarding quest. (Intuitively, it makes sense, since doing more rewarding quests earlier allows us to do them again later.) If no quests are available, we do nothing.

    To implement this, sort the quests in decreasing order, and 0 0 0-index them. On day i i i we should do quest i i i m o d mod mod k k k, provided that this value is less than n n n. This is because after every k k k days, we cycle back to the first quest. Thus we solved the problem for a fixed k k k in O ( d ) O(d) O(d) with O ( n l o g n ) O(nlogn) O(nlogn) precomputation to sort the array.

    Now to solve the problem, we can binary search on the answer, since if some k k k works, then all smaller k k k work. The minimum value of k k k is 0 0 0, and the maximum value is n (for larger k k k, we won’t be able to do the same quest multiple times anyways, so it’s useless to consider them).

    If we find that k k k always goes towards the smaller end of our binary search and k = 0 k=0 k=0 still fails, we output I m p o s s i b l e Impossible Impossible. If we find that k k k always goes towards the larger end of our binary search and k = n k=n k=n still fails, we output I n f i n i t y Infinity Infinity. Otherwise, just output k k k.

    The overall time complexity is O ( n l o g n + d l o g n ) O(nlogn+dlogn) O(nlogn+dlogn).

    Remark. It is not hard to improve the solution to O ( n l o g n ) O(nlogn) O(nlogn). Originally, I proposed the problem this way, but we ended up removing this part of the problem because the implementation of this solution was tricky enough.

    #include
    using namespace std;
    
    typedef long long LL;
    const int N = 200010;
    LL a[N];
    
    int main()
    {
        int T=1;cin>>T;
        while(T--)
        {
            LL n,c,d;cin>>n>>c>>d;
            for(int i=1;i<=n;i++) cin>>a[i];
    
            sort(a+1,a+n+1);
            reverse(a+1,a+n+1);
            for(int i=2;i<=n;i++) a[i]+=a[i-1];
    
            if(a[1]*d<c)
            {
                cout<<"Impossible"<<endl;
                continue ;
            }
    
            if(a[min(n,d)]>=c)
            {
                cout<<"Infinity"<<endl;
                continue ;
            }
    
            auto check=[&](int mid){
                LL sum=0;
                LL dd=d/mid;
                LL yy=d%mid;
                if(mid>=n) sum+=dd*a[n];
                else sum+=dd*a[mid];
    
                if(yy>=n) sum+=a[n];
                else sum+=a[yy];
    
                if(sum<c) return false;
                else return true;
            };
    
            int l=1,r=200000;
            while(l<r)
            {
                int mid=(l+r+1)>>1;
                if(check(mid)) l=mid;
                else r=mid-1;
            }
            cout<<l-1<<endl;
        }
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
  • 相关阅读:
    基于径向基函数RBF神经网络的非线性函数拟合研究-含Matlab代码
    LeetCode 周赛 340,质数 / 前缀和 / 极大化最小值 / 最短路 / 平衡二叉树
    【PAT甲级 - C++题解】1011 World Cup Betting
    【机器学习笔记】
    S7-1200PLC通过远程工具实现上传下载或修改PLC程序的具体方法
    Python重要知识点filter_map_partial_reduce_sorted内置函数的使用方法
    C++-容器-string:string的大小和容量
    手把手教你定位线上MySQL锁超时问题,包教包会
    Docker Cgroups资源控制
    R语言ggplot2可视化:gganimate包创建动态柱状图动画(gif)、使用transition_states函数在动画中沿给定维度逐步显示柱状图
  • 原文地址:https://blog.csdn.net/qq_52792570/article/details/128000268
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号