UVA 10970 第一次比赛 D题 (后面才补的)
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题 (后面才补的)的更多相关文章
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- 贪心水题。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 ...
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- CSDN挑战编程——《金色十月线上编程比赛第二题:解密》
金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...
- UVA.11636 Hello World! (思维题)
UVA.11636 Hello World! (思维题) 题意分析 这题挺水的,还是错了几发. QWQ. 有一个同学打了一行hello world,现在他想打n行hello world,请问最少复制粘 ...
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- UVa 1586 Molar mass --- 水题
UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现 ...
- UVa 272 Tex Quotes --- 水题
题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Q ...
随机推荐
- MATLAB 实用函数
MATLAB个人工具箱(MATLAB) mymail.m 可以利用MATLAB发送邮件(支持附件和群发),非常实用的函数,适用于:耗时很长的脚本完成后通知作者:外加定时器后用于信息推送:家庭监视器紧急 ...
- Flex 列表控件中的操作
主要操作包括:显示提示,使用图标,编辑列表条目中数据. 1.使用数据提示: 当鼠标停留在条目上时,可以显示该条目的相关数据提示. 当利用滚动条时,可以显示滚动条的相关提示. 在列表控件中使用showD ...
- python其中一个子线程,则退出全部线程,再退出进程
import threading, signal is_exit = False def write_login(self): global is_exit write_log('login rsyn ...
- CODEVS 1001 舒适的路线
思路:先按照速度大小对边排序,再枚举最终路径中的速度最大值,并查集,更新答案 #include<iostream> #include<vector> #include<a ...
- 生成Excel直接以流或字节形式发给客户端,无需在服务生成一个实体文件。
public ActionResult ExportAgentBooking(string Company_Id, string Company_Name)//Altman.Web.BCDAdmin. ...
- 使用HTTP协下载文件
通过发送HTTP请求,下载文件 头文件: #ifndef __HTTP__ #define __HTTP__ #include <stdio.h> #include <stdlib. ...
- C# 16进制与字符串、字节数组之间的转换(转)
1.请问c#中如何将十进制数的字符串转化成十六进制数的字符串 //十进制转二进制 Console.WriteLine("十进制166的二进制表示: "+Convert.ToSt ...
- 【好文要转】Python:模拟登录以获取新浪微博OAuth的code参数值
[转自]http://www.tuicool.com/articles/zAz6zi [原文]http://blog.segmentfault.com/hongfei/1190000000343851 ...
- 完成了server和client的框架设计
界面暂且也不搞.先把框架搭建起来.
- xcode不能连接svn以及不能导入的解决方法
配置svn的方法不多说,网上一堆.这里要说的是怎么解决连接不上svn以及在xcode中不能修改svn目录的问题. 首先,xcode连接不上linux的svn,一般来说,问题就出在端口上.svn的默 ...