比赛--大巧克力问题--解题报告

大巧克力问题

题目大意:

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.

要求:

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

题目分析:

题目内容很多,但题目很简单,前面说了很多没用的东西。根据给出的样例分析,可以判断出一次只能将巧克力分成两块,所以切的次数a=M*N-1。

程序代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4
 5 int M[300];
 6 int N[300];
 7
 8 int main()
 9 {
10     int M,N,a;
11     while(scanf("%d%d",&M,&N)!=EOF)
12     {
13         a=M*N-1;
14         cout<<a<<endl;
15     }
16     return 0;
17 }

心得:

这道题目很简单,但由于比赛心情很烦躁,所以没有好好看这道题。比赛完后再看这道题才发现这道题原来如此简单。这次比赛我看到了和别人之间的差距,我应该多做一些题目,好好看一下C语言的基础知识。下次比赛要调整好自己的心态。

时间: 2024-10-17 05:42:00

比赛--大巧克力问题--解题报告的相关文章

POJ 1905(集训比赛2B_A题)解题报告

题目链接:http://poj.org/problem?id=1905 --------------------------------------------------------- 题意:一个线段,给出长度.加热温度及热膨胀系数,线段加热后变为圆弧的一部分,要求求弧顶长度为多少. 思路:简单的画一下图,发现几何关系还是比较明确的,但是发现x的数学表达式并不容易解出来,所以采用二分法求值的方法.选择二分的对象很重要,直接选择对要求的x进行二分,避免角度误差太大. 代码: #include <

比赛--可乐商店问题--解题报告

可乐商店问题 题目大意: Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop,you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how manyfull bottles of coco-cola can you

比赛--十进制转换十六进制--解题报告

十进制转换十六进制问题 题目大意: 把十进制整数转换为十六进制,格式为0x开头,10~15由大写字母A~F表示. 要求: Input 每行一个整数x,0<= x <= 2^31. Output 每行输出对应的八位十六进制整数,包括前导0. 输入样例: Input 0 1023 Output 0x000000000x000003FF 题目分析: 用十六进制格式转换符输出 程序代码: 1 #include<cstdio> 2 #include<iostream> 3 usi

比赛--整理花园问题--解题报告

整理花园问题 题目大意: 有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请问这笔钱如何分给A.B 二位太太较为恰当?A 应得多少元?90/(5+4)*5=$50 元?如果这么想你就上当了!正确答案是60 元.如果没想通的话再想想吧. 下面回答一个一般性的问题:假定A 太太工作了x 天,B 太太工作了y 天,C 太太出了90元,则A 太太应得多少元?输入保证二位太太均

比赛--建金字塔问题--解题报告

建金字塔问题 题目大意: Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 +

POJ 3122 (集训比赛2B_B题)解题报告

题目链接:http://poj.org/problem?id=3122 -------------------------------------------------------- 题意:每人只能从一个派里面切割,要求每个人的派的面积相等,求这个最大面积. 思路:二分法,下限是所有人从最小的里面切割,上限是所有派都完全分割.每次进行二分,判断解是否可行,通过可行性,对上下限进行调整,最终得到结果. 代码: #include <cstdio> #include <cmath> i

CodeForces 551C(集训比赛2B_C题)解题报告

题目链接:http://codeforces.com/problemset/problem/551/C --------------------------------------------------------------------------------- 题意:有n个地点,每个地点有箱子,然后有一定人数,每个人从第i个位置移动到第i+1的位置花费1S,每个人移动一个箱子花费1S,要求把所有箱子全部移除花费的最小时间是多少 思路:二分+贪心的思想,每次对一名学生进行判断.对所求时间进行

NOI2012 骑行川藏 解题报告

当我还没看别人的解题报告时,我用了三分法做了40%的数据. 围观大神的解题报告,要通过100%的数据要用到拉格朗日乘数法求得最值. Wiki上的解释是这样的:Wikipedia Wiki的解释我自己看不太懂,下面这个视频可能让你能对拉格朗日乘数法有更好的认识:麻省理工学院<拉格朗日乘数法> 下面介绍一下拉格朗日乘数法是如何工作的: 问题:在g(x1, x2, x3, ..., xn) = c的约束条件下,求f(x1, x2, x3, ..., xn)的最值. 我们把问题具体化一下:令g(x,

杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告

杭州电子科技大学Online Judge 之 "确定比赛名次(ID1285)"解题报告 巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozhuo) Problem Description 有N个比赛队(1<=N<=500).编号依次为1,2,3,.....N进行比赛.比赛结束后.裁判委员会要将全部參赛队伍从前往后依次排名. 但如今裁判委员会不能直接获得每一个队的比赛成绩,仅仅知道每场比赛的结果.即P1赢P2,用P1.P2表示,排名时P