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 <= ...
随机推荐
- [J2EE] 在Web如何取得相关路径
来自网络,自己整整一下: request.getRealPath("url"); // 虚拟目录映射为实际目录,不建议使用,使用ServletContext.getRealPath ...
- BZOJ 3289: Mato的文件管理 莫队+BIT
3289: Mato的文件管理 Description Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是加密过的 ...
- 主流IM协议简介
四种主流的IM协议, XMPP协议.即时信息和空间协议(IMPP).空间和即时信息协议(PRIM).针对即时通讯和空间平衡扩充的进程开始协议SIP(SIMPLE). XMPP协议: 在这四种协议中,X ...
- android常用对话框封装
在android开发中,经常会用到对话框跟用户进行交互,方便用户可操作性:接下来就对常用对话框进行简单封装,避免在项目中出现冗余代码,加重后期项目的维护量:代码如有问题欢迎大家拍砖指正一起进步. 先贴 ...
- python装饰器--@property
@property 考察 Student 类: class Student(object): def __init__(self, name, score): self.name = name sel ...
- MySQL导入sql脚本 导出数据库
导出数据库 不能停止服务 cd /var/lib/mysql (进入到MySQL库目录,根据自己的MySQL的安装情况调整目录) mysqldump -u用户名 -p 数据库名 > 导出的文件名 ...
- Android拓展系列(12)--使用Gradle发布aar项目到JCenter仓库
目的 发布自己的android library(也就是aar)到公共的jcenter仓库,所有的人都能用gradle最简单的方式引用. 为什么选择jcenter,它兼容maven,而且支持更多形式仓库 ...
- poj2796 维护区间栈//单调栈
http://poj.org/problem?id=2796 题意:给你一段区间,需要你求出(在这段区间之类的最小值*这段区间所有元素之和)的最大值...... 例如: 6 3 1 6 4 5 2 以 ...
- Delphi 2009 泛型容器单元(Generics.Collections)[1]: TList<T>
Delphi 2009 新增了泛型容器单元: Generics.Collections, 同时还有一个 Generics.Defaults 单元做支持. Generics.Collections 包含 ...
- http://blog.csdn.net/a491057947/article/details/46724707
http://blog.csdn.net/a491057947/article/details/46724707