zoukankan      html  css  js  c++  java
  • Two Cakes

    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 n, a 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.

    Example
    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.

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    using namespace std;
    int main()
    {
        int n,a,b,m = 0;
        cin>>n>>a>>b;
        for(int i = 1;i < n;i ++)
        {
            int d = min(a/i,b/(n - i));
            if(d > m)m = d;
        }
        cout<<m;
    }
  • 相关阅读:
    [转载]Netmsg 局域网聊天程序
    [转载] VC6 STLport5.1.4 /STLport4.6.2 编译,安装
    Project Euler Problem 17
    [转载]Singleton的一个基类实现
    [翻译]进化游戏的层次结构 用组件来重构你的游戏实体
    [转载]使用 WSAAsyncSelect 的 Winsock 编程模型
    一种简单定义FourCC常量的方法 (C/C++)
    Permissions 0755 for '/data/user/lxb/.ssh/id_rsa' are too open.
    外键约束之Mysql
    parted
  • 原文地址:https://www.cnblogs.com/8023spz/p/8364821.html
Copyright © 2011-2022 走看看