首页 > 其他分享 >(UVA)Big Chocolate

(UVA)Big Chocolate

时间:2023-05-04 14:33:59浏览次数:37  
标签:Big each number chocolate split input UVA Chocolate he


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

 



Amirkabir University of Technology - Local Contest - Round #2


     题意:求一个大巧克力需要切多少刀才可以分成面积为1*1的小块(每次只能切一块)。





#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n,m;
    while(cin >> n >>m)
    {
        cout << n*m-1 << endl;
    }
    return 0;
}



标签:Big,each,number,chocolate,split,input,UVA,Chocolate,he
From: https://blog.51cto.com/u_14834528/6242755

相关文章

  • Java中进行高精准度坐标数据计算使用BigDecimal(计算距离、开平方)
    场景Java中使用java.awt.geom.Point2D进行坐标相关的计算(距离、平方等):https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/126072919Java中使用JTS对空间几何计算(读取WKT、距离、点在面内、长度、面积、相交等):https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article......
  • JBIG2图像查看器
    JBIG2文件格式是由ISO/IEC14492创建的光栅文件格式。本质上是一种传真机用的图像编码。现在大量使用在PDF中,用于存储二值图,可以获得1:100的压缩率。能够显著减小PDF文件体积。JBIG2格式是用于双色调(黑白)图像的行业标准无损、有损和有损到无损压缩文件格式。与 JBIG、CCITTG3......
  • ImportError: numpy.core.multiarray failed to import (import pyBigWig)
     ---------------------------------------------------------------------------RuntimeErrorTraceback(mostrecentcalllast)RuntimeError:modulecompiledagainstAPIversion0x10butthisversionofnumpyis0xd.Checkthe......
  • UVA 12177 First Knight
    (提醒:原题面是\(m\)行\(n\)列,这里改成了\(n\)行\(m\)列)首先很好想到设\(dp_{u,v}\)为\((u,v)\)的期望步数\(dp_{u,v}=\begin{cases}\sum_{i=1}^4dp_{u+du_i,v+dv_i}\timesp_i&(u\not=n\operatorname{or}v\not=m)\\0&(u=n\operator......
  • CF1477F Nezzar and Chocolate Bars 题解
    题意:有一根长为\(1\)的巧克力,已经被切了\(m-1\)刀被分成\(m\)分,接下来每次在整根长度为\(1\)的巧克力上均匀随机一个点切一刀,求每一小段巧克力长度均小于一个给定值\(K\)需要的期望次数。引理:Irwin-Hall分布:对于\(n\)个在\([0,1]\)内均匀分布的实数随机变量,它们......
  • linux cpufreq framework(5)_ARM big Little driver
    1.前言也许大家会觉得奇怪:为什么Linuxkernel把对ARMbig·Lttile的支持放到了cpufreq的框架中?众所周知,ARM的big·Little架构,也称作HMP(具体可参考“LinuxCPUcore的电源管理(2)_cputopology”中相关的介绍),通过在一个chip中封装两种不同类型的ARMcore的方式,达到性能和功耗的......
  • Sololearn website big changes All In One
    SololearnwebsitebigchangesAllInOneLearnPythonoldversionJumptoourbestPythoncourse!Thisoldversionisabouttogoonpermanentvacation.这个旧版本即将永久休假https://www.sololearn.com/learning/1158newversionhttps://www.sololearn.com/l......
  • Gangsters UVA - 672
     一家饭店,有一扇大小会变得门,变化范围为[0,k]。每过一单位时间你可以让门的大小+1,-1,或者不变。客人会在不同的时间来吃饭,但是如果门的大小和他们希望的值不一样,他们就不会进来并且直接消失。吃饭要花钱,现在问饭店最多能赚多少钱。  F[i][j]=max(F[i-1][j]+v,F[i-1][j-1......
  • BigDecimal的setScale常用方法(ROUND_UP、ROUND_DOWN、ROUND_HALF_UP、ROUND_HALF_DOW
    BigDecimal的setScale四大常用方法总结//设置小数点后第三位数字一大一小观察效果BigDecimalnum=newBigDecimal("3.3235667");BigDecimalnumOne=newBigDecimal("3.3275667");1、ROUND_UP:进位制:不管保留数字后面是大是小(0除外)都会进1//ROUND_UP--进位制:不管保留数......
  • 当 SQL Server(mssql-jdbc) 遇上 BigDecimal → 精度丢失,真坑!
    开心一刻中午和哥们一起喝茶哥们说道:晚上喝酒去啊我:不去,我女朋友过生日哥们瞪大眼睛看着我:你有病吧,充气的过什么生日我生气到:有特么生产日期的好吧需求背景系统对接了外部系统,调用外部系统的接口需要付费,一个接口一次调用付费0.03元同一个......