ACM第三次比赛 Big Chocolate

Problem G

Big Chocolate

Mohammad has recently visited Switzerland . As he loves his friends very much, he decided to buy some chocolate for them, but as this fine chocolate is very expensive(You know Mohammad is a little BIT stingy!), he could only afford buying one chocolate, albeit a very big one (part of it can be seen in figure 1) for all of them as a souvenir. Now, he wants to give each of his friends exactly one part of this chocolate and as he believes all human beings are equal (!), he wants to split it into equal parts.

The chocolate is an rectangle constructed from  unit-sized squares. You can assume that Mohammad has also  friends waiting to receive their piece of chocolate.

To split the chocolate, Mohammad can cut it in vertical or horizontal direction (through the lines that separate the squares). Then, he should do the same with each part separately until he reaches  unit size pieces of chocolate. Unfortunately, because he is a little lazy, he wants to use the minimum number of cuts required to accomplish this task.

Your goal is to tell him the minimum number of cuts needed to split all of the chocolate squares apart.

Figure 1. Mohammad’s chocolate

The Input

The input consists of several test cases. In each line of input, there are two integers , the number of rows in the chocolate and , the number of columns in the chocolate. The input should be processed until end of file is encountered.

The Output

For each line of input, your program should produce one line of output containing an integer indicating the minimum number of cuts needed to split the entire chocolate into unit size pieces.

Sample Input

2 2

1 1

1 5

 

Sample Output

3

0

4

程序分析:此题并没有太多好说的,就是把一块巧克力切M*N块,可以画图来解决,会让人感觉很清楚的。

程序代码:

#include <cstdio>
#include <iostream>
using namespace std;

int main( )
{int a ,b,t;
while(scanf("%d %d",&a,&b)!=EOF)
{
  int n1,n2;
         n1=(a-1)+a*(b-1);
        n2=(b-1)+b*(a-1);
    t=(n1<n2)?n1:n2;
        printf("%d\n",t);
    }

return 0;
}
时间: 2024-10-27 10:58:58

ACM第三次比赛 Big Chocolate的相关文章

ACM第三次比赛UVA11877 The Coco-Cola Store

Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop, you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how many full bottles of coco-cola can you drink? Inp

[ACM] hdu 1285 确定比赛名次 (拓扑排序)

确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10358    Accepted Submission(s): 4046 Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直

最近打的三场比赛的总结

10.25 上午 省常中模拟赛 比赛题目刚发下来,看到出题人之后我就变得紧张起来,因为暑假的时候也做过一份他出的题,题目难到连全场最高分也不过 100 多分,所以又一次做到他出的题难免有些心理阴影. 这种心态直接导致了我在第一题上的失误.由于在心里认为这场模拟赛的难度应该较高,导致我对于第一题几乎不假思索就认为是动规,而根本没有往更简单的方向去想.我一开始想到的是区间动规,但是发现只能拿 50 分,想了一会儿还是没什么思路,于是先把区间动规打好然后打第二题. 第二题是一道比较不错的题,但是由于强

acm的第一场比赛的总结

6.4-6.5号很激动的去湖南湘潭打了一场邀请赛,这是第一次acm的旅程吧.毕竟大一上册刚开始接触c,然后现在就能抱着学长的大腿(拖着学长的后腿)打比赛,也是有一点小小的激动. 第一天很早就起床了,由于周五的时候敢色彩构成的作业敢到凌晨两点,然后周五早上8点起床然后在晨光收作业到十点,最后兴冲冲的走到办公室结果老师人不在,然后拖着三大袋的作业打电话给老师,然后等了一个小时,于是周六早上出奇的累.然后再高铁上睡了5个小时(虽然愣是没睡着),然后就到湘潭大学签到,最后打了一场挂0的热身赛(1小时),

2015年ACM长春区域赛比赛感悟

距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的.在接到通知后,我便开始临阵抱佛脚,课也不怎么听了,上课把时间全都用在了看各种算法上,回到实验室便整理模板.开cf练手.在去比赛前,已经将所看过的算法模板都整理好了. 周五上午9点三刻左右,我们便出发了,需要经历12个小时才能到达我们此次的目的地——长春,途中我还将计算几何稍微看了一下.直到晚上11点

6、Cocos2dx 3.0游戏开发的基本概念找个小三场比赛

重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27689713 郝萌主友情提示: 人是习惯的产物,当你习惯快乐时.记忆里的不愉快就消失了. 游戏開始之前 经过之前的学习,我们已经能够开发一个最主要的 Cocos2d-x 游戏了,这个游戏包含一张背景图片和一个退出游戏的按 钮,可是这距离完毕一个完整.有用的游戏还非常遥远.在这一章节中,我们将首先抛开 Cocos2d,介绍游戏开发的基本概念.然后结合

ACM: HDU 1285 确定比赛名次 - 拓扑排序

HDU 1285 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前.现在请你编程序确定排名

UVA_11877.第三次比赛C题:The Coco Cola

题目: 有一个coco cola小店,你可以用三个空瓶换一瓶coco cola饮料,如果你有n个空瓶,你可以喝到多少瓶饮料? 输入输出要求: intput:最多有10组案例,每组输入一个整数,0不被处理操作. Output:每组案例输出你能喝到的饮料数. sample intput: 3 10 81 0 sanple output: 1 5 40 代码如下: #include<iostream> #include<cstdio> using namespace std; int m

acm专题三1006

Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:<br><br>有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?<br><img src=../data/images/2084-1.jpg><br>已经告诉你了,这是个DP的题目,你能AC吗? Input 输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1