zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 35 B. Two Cakes【枚举/给盘子个数,两份蛋糕块数,最少需要在每个盘子放几块蛋糕保证所有蛋糕块都装下】

    B. Two Cakes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.

    Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:

    1. Each piece of each cake is put on some plate;
    2. Each plate contains at least one piece of cake;
    3. No plate contains pieces of both cakes.

    To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.

    Help Ivan to calculate this number x!

    Input

    The first line contains three integers na and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.

    Output

    Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.

    Examples
    input
    5 2 3
    output
    1
    input
    4 7 10
    output
    3
    Note

    In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.

    In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.

    【题意】:给盘子个数n,两份蛋糕块数a和b,需要在每个盘子最多放几块蛋糕保证所有蛋糕块都装下。

    【分析】:从小到大枚举i(放几块蛋糕),若a / i + b / i >= n 则合法,i 的最大枚举量是min(a,b),不然可能有多余的 a % i 没地方放。

    【时间复杂度&&优化】:

    【代码】:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,a,b;
        cin>>n>>a>>b;
        for(int i=min(a,b);;i--)
        {
            if(a/i+b/i>=n) return 0*printf("%d
    ",i);
        }
    }
    技巧枚举
  • 相关阅读:
    Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!
    showModalDialog和showModelessDialog的使用
    如何在GridView中使用DataFromatString
    GridView/DataGrid单元格不换行的问题
    要Gmail、Orkut邀请的请留下你的邮箱
    How to reset security settings back to the defaults
    ASP.NET 2.0 学习笔记 1: session 与 script 应用
    关闭主窗体而不退出主程序 以及如何获取操作系统的关闭、注销信息
    ASP.NET 2.0 学习笔记 2: 页面间传值
    Windows 系统常用设置方法与技巧
  • 原文地址:https://www.cnblogs.com/Roni-i/p/8143916.html
Copyright © 2011-2022 走看看