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的更多相关文章

  1. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  2. hdu----(4301)Divide Chocolate(状态打表)

    多校综合排名前25名的学校请发送邮件到HDUACM@QQ.COM,告知转账信息(支付宝或者卡号) Divide Chocolate Time Limit: 2000/1000 MS (Java/Oth ...

  3. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  4. 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/ ...

  5. codeforces 678C C. Joty and Chocolate(水题)

    题目链接: C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  7. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  8. 【暑假】[深入动态规划]UVAlive 4794 Sharing Chocolate

    UVAlive 4794 Sharing Chocolate 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12055 ...

  9. Codeforces Problem 598E - Chocolate Bar

    Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...

随机推荐

  1. 最实用的APP界面设计知识,有温度的APP设计(转)

    在逛简书的时候,无意之间看到了这样的一篇非常有意思的app设计博文.顾25学堂的摘录了其中的一些关于移动端APP界面设计的精华.分享给25学堂的app设计师们. 当然,下面的这些app设计知识点是来自 ...

  2. LeetCode——Reverse Integer(逆置一个整数)

    问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321   Ha ...

  3. Arduino101学习笔记(八)—— 函数库

    /*********最小值*********/ min() //实现:#define min(a,b) ((a)<(b)?(a):(b)) /*********最大值*********/ max ...

  4. Arduino101学习笔记(五)—— 模拟IO

    1.配置IO管脚 //***************************************************************************************** ...

  5. 数字信号处理实验(四)——数字滤波器结构

    一.滤波器结构 1.IIR滤波器 (1)系统函数   (2)差分方程   (3)级联形式:   (4)并联形式   2.FIR滤波器 (1)系统函数   (2)差分方程   (3)级联形式:   (4 ...

  6. LoadRunner 脚本学习 -- 随机函数运用

    直接上码 Action() { int randnum; randnum = rand()%+; lr_output_message("随机得到的数是:%d", randnum); ...

  7. 利用scp传输文件小结

    从本地复制到远程 scp mysql-5.5.29-linux2.6-x86_64.tar.gz 192.168.1.11:/opt 指定端口: scp -P 60022 /opt/ray/nginx ...

  8. hdu3535 背包大杂汇

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3535 //不想写题解,这道题让我对背包的理解更深了,我相信我不会忘记的.... 代码: # ...

  9. 我的c++学习(8)运算符重载和友元

    运算符的重载,实际是一种特殊的函数重载,必须定义一个函数,并告诉C++编译器,当遇到该运算符时就调用此函数来行使运算符功能.这个函数叫做运算符重载函数(常为类的成员函数). 方法与解释 ◆ 1.定义运 ...

  10. 简单的css 菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...