• CODEFORCES Problem-1954A.Painting the Ribbon(好题,非常打开思维)


    time limit per test

    2 seconds

    memory limit per test

    512 megabytes

    input

    standard input

    output

    standard output

    Alice and Bob have bought a ribbon consisting of n𝑛 parts. Now they want to paint it.

    First, Alice will paint every part of the ribbon into one of m𝑚 colors. For each part, she can choose its color arbitrarily.

    Then, Bob will choose at most k𝑘 parts of the ribbon and repaint them into the same color (he chooses the affected parts and the color arbitrarily).

    Bob would like all parts to have the same color. However, Alice thinks that this is too dull, so she wants to paint the ribbon in such a way that Bob cannot make all parts have the same color.

    Is it possible to paint the ribbon in such a way?

    Input

    The first line contains one integer t𝑡 (1≤t≤1000) — the number of test cases.

    Each test case consists of one line containing three integers n𝑛, m𝑚 and k𝑘 (1≤m,k≤n≤50) — the number of parts, the number of colors and the number of parts Bob can repaint, respectively.

    Output

    For each test case, print YES if Alice can paint the ribbon so that Bob cannot make all parts have the same color. Otherwise, print NO.

    You can print every letter in any register. For example, Yes, yes, yEs will all be recognized as positive answer.

    这道题目的大致意思是:有n个部分要上色,bob选择最多m种颜色上色,bob不希望颜色都一样,alice希望颜色都一样,alice可以改变k个部分,问是否颜色一致,若是“NO”不是“YES”

    这道题跟算法就基本无关了,这就不是程序竞赛了,这就是数学竞赛了,数学好的同学应该会有好的办法来解决他,直接放代码吧:

    1. #include
    2. using namespace std;
    3. int t,n,m,k;
    4. int main()
    5. {
    6. cin >> t;
    7. while(t--){
    8. cin >> n >> m >> k;
    9. int max_color = (n + m - 1) / m;
    10. if(max_color >= n - k) cout << "NO" << endl;
    11. else cout << "YES" << endl;
    12. }
    13. return 0;
    14. }

    简单解释一下,max_color和n - k(也就是alice改变不了的部分)做比较,如果max_color大于等于n - k说明所有都可以是一样的颜色

    以下是用库函数ceil求max_color代码:

    1. #include
    2. using namespace std;
    3. int t,n,m,k;
    4. int main()
    5. {
    6. cin >> t;
    7. while(t--){
    8. cin >> n >> m >> k;
    9. int max_color = ceil(n / m);
    10. if(max_color >= n - k) cout << "NO" << endl;
    11. else cout << "YES" << endl;
    12. }
    13. return 0;
    14. }
    1. #inlcude || #include
    2. ceil(double(m) / n) m / n 向上取整
    3. floor(double(m) / n) .....向下取整

    加油

  • 相关阅读:
    回归预测 | MATLAB实现TCN时间卷积神经网络多输入单输出回归预测
    借助MLOps平台简化联邦学习工作流程
    网口工业相机之丢包问题排查
    【租车骑绿道】python实现-附ChatGPT解析
    架构解析:Dubbo3 应用级服务发现如何应对双 11 百万集群实例
    图片转excel表格怎么弄?有何密笈?
    申请ISO50430建筑体系认证有哪些注意问题?
    林业草原防火智能可视化平台
    CSS详细解析二
    【gpt实践】同时让chatgpt和claude开发俄罗斯方块
  • 原文地址:https://blog.csdn.net/AuRoRamth/article/details/139636838