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-)+a*(b-);
n2=(b-)+b*(a-);
t=(n1<n2)?n1:n2;
printf("%d\n",t);
} return ;
}
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 sho ...
- acm的第一场比赛的总结
6.4-6.5号很激动的去湖南湘潭打了一场邀请赛,这是第一次acm的旅程吧.毕竟大一上册刚开始接触c,然后现在就能抱着学长的大腿(拖着学长的后腿)打比赛,也是有一点小小的激动. 第一天很早就起床了,由 ...
- 2015年ACM长春区域赛比赛感悟
距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的. ...
- [ACM] hdu 1285 确定比赛 (拓扑排序)
确定比赛 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- [ACM] hdu 1285 确定比赛名次 (拓扑排序)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- #【Python】【demo实验23】【练习实例】【 三人比赛顺序问题 】
原题: 两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. 我的 ...
- ACM: HDU 1285 确定比赛名次 - 拓扑排序
HDU 1285 确定比赛名次 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- ACM、OI等比赛中的程序对拍问题
多年前请教于ZXYTIM(zxy)大牛,现在把windows环境下的版本贴出来. 手动数据调试效率太低,程序对拍还是非常实用的,特别适用于OI.蓝桥杯等这些比赛规则.可以用于暴力与AC算法之间的对拍. ...
- 6、Cocos2dx 3.0游戏开发的基本概念找个小三场比赛
重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27689713 郝萌主友情提示: 人是习惯的产物,当你 ...
随机推荐
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- WPF自学笔记
WPF使用哪几种元素作为顶级元素: 1. Window元素 2. Page元素(与Window元素类似,用于可导航的应用程序) 3. Application元素(定义应用程序资源和启动设置) PS:在 ...
- 加特殊符号星号斜杠反斜杠/* \ */ !important等让css实现兼容各个浏览器的技巧的代码
在编写css样式表的时候常常会碰到一写浏览器兼容的问题,象是不同内核的浏览器显示就不一定相同,不同版本的的浏览器也会产生上下兼容的问题,如何解决这些问题成了我们苦恼的问题,如果你对css hac ...
- [转]SAP中找表的方法
http://blog.chinaunix.net/uid-24063584-id-2642334.html 分类: 18种根据屏幕字段查找数据库表数据的技巧 帮助 18种根据屏幕字段查找潜在数据 ...
- Spring注解配置
配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...
- CSS3 总结-2
过渡属性 下面的表格列出了所有的转换属性: 属性 描述 CSS transition 简写属性,用于在一个属性中设置四个过渡属性. 3 transition-property 规定应用过渡的 CSS ...
- Nginx 之六: Nginx十万并发优化
操作 操作 Nginx 之六: Nginx十万并发优化
- linux禁ping和允许ping的方法
一.系统禁止ping [root@linuxzgf ~]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 二.系统允许ping [root@li ...
- A package manager for Qt
官网 http://www.qpm.io/ A package manager for Qt 注释:这个网站类似JavaScript的包管理器的网站https://www.npmjs.com/ 都是给 ...
- php 用户访问菜单页面,必须登录,判断用户是否登录
<pre name="code" class="python"># 本节课大纲: 一.空模块和空操作 1.空操作 function _empty($ ...