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 ;
}

UVA 10970 第一次比赛 D题 (后面才补的)的更多相关文章

  1. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  2. 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

    UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...

  3. UVa 1583 Digit Generator --- 水题+打表

    UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...

  4. CSDN挑战编程——《金色十月线上编程比赛第二题:解密》

    金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...

  5. UVA.11636 Hello World! (思维题)

    UVA.11636 Hello World! (思维题) 题意分析 这题挺水的,还是错了几发. QWQ. 有一个同学打了一行hello world,现在他想打n行hello world,请问最少复制粘 ...

  6. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  7. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  8. UVa 1586 Molar mass --- 水题

    UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现 ...

  9. UVa 272 Tex Quotes --- 水题

    题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Q ...

随机推荐

  1. http是什么?

    http HyperText Transfer Protocol 超文本传输协议,是一个应用层通信协议. 可以用wireshark抓取.

  2. 使用Spring的Property文件存储测试数据 - 添加测试数据

    测试数据直接写在Property文件中,如下图: application.properties是系统自动生成,我添加了两个Property文件:HomeTestData.properties和moto ...

  3. C/C++笔试经典程序(二)

    1.下面5个函数哪个能够成功进行两个数的交换? swap1传的是值的副本,在函数体内被修改了形参p.q(实际参数a.b的一个拷贝),p.q的值确实交换了,但是它们是局部变量,不会影响到主函数中的a和b ...

  4. [C++11] Effective Modern C++ 读书笔记

    本文记录了我读Effective Modern C++时自己的一些理解和心得. item1:模板类型推导 1)reference属性不能通过传值参数传入模板函数.这就意味着如果模板函数需要一个refe ...

  5. 为网站加入Drupal星球制作RSS订阅源

    目前中文 Drupal 星球的版块还未成立,但大家的积极性挺高,不少站长都已经调整好自己的网站,生成了可供Drupal Planet 使用的RSS订阅源. 如果你也想让网站做好准备,可以不必再花上不少 ...

  6. (转载)MonoBehaviour的事件和具体功能总结

    分享一点MonoBehaviour的事件和具体功能总结的基础知识,苦于Visual Studio 2013没有对MonoBehaviour的行为做出智能提示,写个函数都要全手打,记性好的将就着手打,脑 ...

  7. 【翻译习作】 Windows Workflow Foundation程序开发

    近期整理硬盘,把09年的翻译习作<Windows Workflow Foundation程序开发>找出来了.现在又把译文过了一遍,做了些修改,贴出来献丑了.原书是<Programmi ...

  8. Tomcat源码分析——SERVER.XML文件的加载与解析

    前言 作为Java程序员,对于Tomcat的server.xml想必都不陌生.本文基于Tomcat7.0的Java源码,对server.xml文件是如何加载和解析的进行分析. 加载 server.xm ...

  9. AX调用.dll

    1,将DLL拷贝到C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin 2,在AOT添加引用,在选择你拷贝的DLL,确定.//Acces ...

  10. angular 页面加载时可以调用 函数处理

    转载于 作者:海底苍鹰地址:http://blog.51yip.com/jsjquery/1599.html 我希望页面加载的时候,我能马上处理页面的数据,如请求API .... 所以这样设置 在某个 ...