Big Chocolate

2024-08-24 22:38
文章标签 big chocolate

本文主要是介绍Big Chocolate,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

我只想说水得一手好水。。。有必要隐藏这么深嘛。。。。

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

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
int main()
{int m, n;while(scanf("%d%d",&m,&n)!=EOF){printf("%d\n", m*n-1);}return 0;
}

这篇关于Big Chocolate的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1103804

相关文章

CodeForces 490D Chocolate

题意: 2块矩形巧克力  如果边长可以整除2  则可以从一半出掰开  吃掉一半  如果可以整除3  则可以从1/3处掰开  吃掉1/3  问  最少吃几次  能使得2块面积相同  输出最后时刻的边长 思路: 面积最多只有10^18  因此形成的面积的种类数最多几万种  我们可以利用面积来暴搜出所有状态  然后找面积相同时的最少步数 PS:数论的方法更好 代码: #include

Codeforces Round #328 (Div. 2)C. The Big Race(数学gcd lcm)

题目连接 题意:比赛时 ,居然理解错题意= =,以为两个人的速度是一样的,然后有个人的只会有一步是w米,另一个人只有一步是b米。。。。 就是一个人每一步是w,一个人每一步是b,终点后是深渊,然后长度是在1–t随机选择一个d作为赛道长度,问不能区分二人胜负的可能。 思路:就是求d%w==d%b = = #include<bits/stdc++.h>using namespace std;

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

题目链接 题意:在n*m的矩形切出面积是k 解法:记忆化搜索 #include<bits/stdc++.h>using namespace std;#define LL long long#define pb push_back#define X first#define Y second#define cl(a,b) memset(a,b,sizeof(a))typedef

[SimCLR v2] Big Self-Supervised Models are Strong Semi-Supervised Learners

1、目的         借助无监督预训练来提升半监督学习的效果 2、方法                  1)unsupervised/self-supervised pretrain                 -> task-agnostic                 -> big (deep and wide) neural network可以有效提升准确性

Qt6中使用qcustomplot时报错:file too big

错误描述:在qt6中使用qcustomplot时报错提示:file too big 提示是.cpp文件太大导致的,需要在.pro文件中再增加一行 QMAKE_CXXFLAGS += "-Wa,-mbig-obj"修改编译器的设置

poj 3031 Big Christmas Tree(水spfa)

http://poj.org/problem?id=3013 题意: Because of a technical difficulty, price of an edge will be (sum of weights of all descendant nodes) × (unit price of the edge).这句话一直没看懂。后面还以为是最小生成树。 正确题意是

1325:算法2-3~2-6:Big Bang

题目描述 复习考研累了的时候看看一集二十分钟左右的《生活大爆炸》也不失为一种乐趣。在剧中Sheldon可以说是一个极品,真不知Leonard是如何忍受这位极品室友成天的唠叨。 你知道么?Sheldon有一个神秘的小本本,记录了所有他从小开始讨厌的人名。Stuart这位漫画店老板就是小本本的一员哦,谁叫他常常毫不客气地挤兑Sheldon,曾多次赌赢过Sheldon呢。 Penny是

codeforces #257 C题Jzzhu and Chocolate

题目地址:http://codeforces.com/contest/450/problem/C 这次CF的时候绝壁脑残了。。。A题和C题都出现了脑残失误。。。唯一一个AC的B题还是被HACK了。。。分数也不多了。。。简直sad。。。。。。。。 这题我的思路是分类讨论,分四种情况。 首先让n>=m,如果不是的话,可以交换。主要是考虑切横的多少刀,竖的多少刀。 1:当k>n+m-2,此时,切

HDU 3046Pleasant sheep and big big wolf(网络流之最小割)

题目地址:HDU 3046 最小割第一发!其实也没什么发不发的。。。最小割==最大流。。 入门题,但是第一次入手最小割连入门题都完全没思路。。。sad。。对最小割的本质还是了解的不太清楚。。 这题就是对每两个相邻的格子的边界都要进行加边,然后求最大流就OK了。 RE了好长时间,注意遍历加边的时候要从1开始,而不是0开始,因为0是源点的。。。(也许只有我才犯这种错误吧。。。)建图不多说了。。

Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

题目地址:传送门 这题虽然是DIV1的C。。但是挺简单的。。只要用线段树分别维护一下横着和竖着的值就可以了,先离散化再维护。每次查找最大的最小值<=tmp的点,可以直接在线段树里搜,也可以二分去找。 代码如下: #include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algori