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-)+a*(b-);
n2=(b-)+b*(a-);
t=(n1<n2)?n1:n2;
printf("%d\n",t);
} return ;
}

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

  1. 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 sho ...

  2. acm的第一场比赛的总结

    6.4-6.5号很激动的去湖南湘潭打了一场邀请赛,这是第一次acm的旅程吧.毕竟大一上册刚开始接触c,然后现在就能抱着学长的大腿(拖着学长的后腿)打比赛,也是有一点小小的激动. 第一天很早就起床了,由 ...

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

    距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的. ...

  4. [ACM] hdu 1285 确定比赛 (拓扑排序)

    确定比赛 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

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

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. #【Python】【demo实验23】【练习实例】【 三人比赛顺序问题 】

    原题: 两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. 我的 ...

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

     HDU 1285 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  8. ACM、OI等比赛中的程序对拍问题

    多年前请教于ZXYTIM(zxy)大牛,现在把windows环境下的版本贴出来. 手动数据调试效率太低,程序对拍还是非常实用的,特别适用于OI.蓝桥杯等这些比赛规则.可以用于暴力与AC算法之间的对拍. ...

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

    重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27689713 郝萌主友情提示: 人是习惯的产物,当你 ...

随机推荐

  1. Curling 2.0(dfs回溯)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15567   Accepted: 6434 Desc ...

  2. Mysql 查询 字符串 (索引和通配符)

    需要查询的 Mission_Info  字段 值   CYVR-0220-1240-ZYTX-1415-1740-ZUUU-9999-9999-ZZZZ-9999-9999-ZZZZ SELECT M ...

  3. python编写工具及配置(notepad++)

    学长跟我说老师实验室里用的ide是pycharm,我用了一天,整体还行,就是加载速度太慢,可是第二天用的时候就卡的想让人骂街,cpu占有率趋近100%,电脑配置不高,我寻思不能因为这个就马上换电脑吧, ...

  4. 「OC」 继承

    一.基本用法 1.设计两个类Bird.Dog 1 // Bird的声明 2 @interface Bird : NSObject 3 { 4 @public 5 int weight; 6 } 7 - ...

  5. 建立dblink,clob

    建立dblink的方法, 如果有个测试库A,要访问生产库里的数据,那么可以直接在测试库A里建立一个dblink,然后数据库A就可以直接访问测试库B的数据了. -- 删除已有的dblink drop d ...

  6. block, inline和inline-block的区别

    display:block元素的特点是:总是在新行上开始:高度,行高以及顶和底边距都可控制:宽度缺省是它的容器的100%,除非设定一个宽度<div>, <p>, <h1& ...

  7. HTML 总结-表单-表单属性

    HTML5 表单属性 HTML5 的新的表单属性 本章讲解涉及 <form> 和 <input> 元素的新属性. 新的 form 属性: autocomplete novali ...

  8. php定时自动执行 需启动第一次

    1 2 3 4 5 6 7 8 9 10 11 12 <? ignore_user_abort(); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行. set_time_li ...

  9. 运用Python语言编写获取Linux基本系统信息(二):文件系统使用情况获取

    本文跟着上一篇文章继续写,上一篇文章的链接 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本.内核.当前时间 一.随便说说 获取文件系统使用情况的思路和上一篇获取主要系统是 ...

  10. LinuxC安装gcc

    使用centos进行C编程的时候使用gcc hello.c提示 bash:gcc:command not found 此时需要给Linux安装gcc命令如下 1 yum -y install gcc ...