Big Chocolate
Big Chocolate
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127
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的巧克力切成单位大小的巧克力;求出削减所有的巧克力块所需的最小刀数的数量。
分析:
如果是正方形(M=N)不管如何切都是一样的,当是长方形时如M>N就先切M-1刀使它变成M块N*1的巧克力,
再将这些巧克力切成单位大小的巧克力。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,m,cut;
while(scanf("%d%d",&n,&m)!=EOF)
{ cut=0;
if(n>m)
cut=n*(m-1)+n-1;
else cut=m*(n-1)+m-1;
cout<<cut<<endl;
}
return 0;
}
Big Chocolate的更多相关文章
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- hdu----(4301)Divide Chocolate(状态打表)
多校综合排名前25名的学校请发送邮件到HDUACM@QQ.COM,告知转账信息(支付宝或者卡号) Divide Chocolate Time Limit: 2000/1000 MS (Java/Oth ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate set
C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...
- codeforces 678C C. Joty and Chocolate(水题)
题目链接: C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input s ...
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...
- 【暑假】[深入动态规划]UVAlive 4794 Sharing Chocolate
UVAlive 4794 Sharing Chocolate 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12055 ...
- Codeforces Problem 598E - Chocolate Bar
Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...
随机推荐
- thinkphp调用phpqrcode.php生成二维码
thinkphp3. 把phpqrcode文件夹放在ThinkPHP\Library\Vendor\下面 phpqrcode下载: http://files.cnblogs.com/files/qho ...
- hdu 4759 大数+找规律 ***
题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y 问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...
- Java Socket编程(转)
Java Socket编程 对于Java Socket编程而言,有两个概念,一个是ServerSocket,一个是Socket.服务端和客户端之间通过Socket建立连接,之后它们就可以进行通信了.首 ...
- [Liferay6.2]启动Tomcat提示APR不能在java类库路径中被找到的解决办法
问题描述 启动liferay之后,在控制台中打印出会打印出以下信息: 信息: The APR based Apache Tomcat Native library which allows optim ...
- 写给自己的web开发资源
web开发给我的感觉就是乱七八糟,而且要学习感觉总是会有东西要学习,很乱很杂我也没空搞,(其实学习这个的方法就是去用它,什么你直接用?学过js么学过jquery么?哈哈,我没有系统的看完过,但是也做出 ...
- zTree学习文档和DEOM
http://tool.oschina.net/apidocs/apidoc?api=ztree3.2%2Fapi%2FAPI_cn.html zTree的API http://www.ztree.m ...
- Callable接口、Runable接口、Future接口
1. Callable与Runable区别 Java从发布的第一个版本开始就可以很方便地编写多线程的应用程序,并在设计中引入异步处理.Thread类.Runnable接口和Java内存管理模型使得多线 ...
- JQ学习(一)
通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行“操作”(actions). jQuery 语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些 ...
- jQuery.lazyload详解
<SCRIPT src="jquery.js" type=text/javascript></SCRIPT> <SCRIPT src="jq ...
- hdu2546 01背包
http://acm.split.hdu.edu.cn/showproblem.php?pid=2546 01背包问题,首先拿出5元买最贵的东西,那接下来就是背包容量m-5,物品数量n-1 的01背包 ...