编程介的小学生 2017-11-16 02:57 采纳率: 20.5%
浏览 611
已结题

Bottles Arrangement

Problem Description
  Hunan cuisine is really wonderful! But if you don’t like spicy food, you will feel terrible since it can be hard for you to find any food without hot pepper here. Big Fan is a student from the north who was not fit to the spicy food in Changsha. He became thinner and thinner because eating little food and maintained his life mostly by drinking water. One day, he found that the wine in Hunan is pretty good, such as Jiugui, Liuyang River, Shaoyang Daqu and so on. He got addicted to it and became an alcoholic, leading a depressed life.
  Now N days have passed and he is sobered. He is surprised to find that there are exactly N×M bottles around him. Another amazing fact is that there are N bottles with height 1 and N bottles with height 2 … N bottles with height M.
Now he is interested in playing with these bottles. He wants to arrange all these bottles in a rectangle with M rows and N columns which satisfied:
(1)In any column, there are no bottles with same height;
(2)In any row, the height difference between any two adjacent bottles is no more than 1.
  He defined a strange function Y which equals the maximum value of the total height of any single row. He is addicted in arranging these rubbish bottles to find the minimal Y. You know that he cannot solve it with his pour IQ. You are his friend and can’t endure his decadence any more. So you decide to help him solve this problem and then bring him back to study.

Input
  There are several test cases. For each case, the input contains one line with two integers M and N (1< M <= 10000, 3 <= N < 2×M, It is guaranteed that N is always odd).
  The input will finish with the end of file.

Output
  For each test case, print the minimal Y in single line.

Sample Input
3 3
3 5

Sample Output
8
11

  • 写回答

1条回答 默认 最新

  • IzuruKamuku 2018-09-02 06:08
    关注

    比如3 1

    答案就是3

    比如3 2

    答案就是 3 3 2

    比如3 3

    答案就是3 3 2 2 1

    那么就发现从M递减 等差数列求和

    #include
    #include
    #include
    #include
    using namespace std;
    int main()
    {
    int N,M;

    while(scanf("%d%d",&M,&N)!=EOF)
    {
        printf("%d\n",(M+(M-(N-1)/2)+1)*(N-1)/4+(M+(M-(N+1)/2)+1)*(N+1)/4);
    }
    
    return 0;
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器