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 M × N rectangle constructed
from M × N unit-sized squares. You can assume that
Mohammad has also M × N 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
M × N 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.
Input
The input consists of several test cases. In each line of input, there are two integers 1 ≤ M ≤ 300, the
number of rows in the chocolate and 1 ≤ N ≤ 300, the number of columns in the chocolate. The input
should be processed until end of file is encountered.
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的巧克力,问把它切成最小单元需要最少切几刀,分开的就不能一起切了。

思路:既然长,宽是N,M,那么就要分成N*M块,自然就需要M*N-1刀了     (当初比赛的时候没有做出来,自己也是够蠢的)

代码如下:

 #include <stdio.h>
int main()
{
int N,M;
while(scanf("%d%d",&N,&M)==)
{
int ans=M*N-;
printf("%d\n",ans);
}
return ;
}

最新文章

  1. AE_复制当前图层
  2. iOS开发——源代码管理——git(分布式版本控制和集中式版本控制对比,git和SVN对比,git常用指令,搭建GitHub远程仓库,搭建oschina远程仓库 )
  3. Action&lt;T1, T2&gt;委托
  4. ruby 除法运算
  5. iOS后台定位实现
  6. HDU 3085 Nightmare Ⅱ (双向BFS)
  7. 算法的优化(C语言描述)
  8. 一.oracle的SQL中group by使用的情况(与聚合函数的关系)
  9. XML DOM 节点
  10. TCP和UDP的差别
  11. Vultr新加坡机房速度怎么样?值得购买吗?最新评测!
  12. 移动端解决input focus后键盘弹出,高度被挤压的问题
  13. Protocol Buffer序列化对比Java序列化.
  14. sessionStorage和localStorage的用法,不同点和相同点
  15. c# IPC实现本机进程之间的通信
  16. jacascript 判断元素尺寸和位置
  17. java class反编译工具----JD-GUI
  18. [Python][小知识][NO.4] wxPython 字体选择对话框(O.O 不知道放到那里就放到这个分类的)
  19. Page Lifecycle API
  20. [POI2004] SZN

热门文章

  1. POJ1979 Red and Black (简单DFS)
  2. maven的安装与配置
  3. 微信公众号发起微信支付 c#
  4. ORA-01810: 格式代码出现两次
  5. CLRS:Insert sort in in c
  6. TCP/IP之大明王朝邮差
  7. CSS 三角形绘制方法
  8. 用绝对路径引用JS、CSS
  9. iOS 微信支付平台集成
  10. node.js回调函数 - 阻塞与非阻塞