UVa 10970

题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=0&problem=1911


题意

m*n的矩形巧克力,要切成1*1,不能一次切两块,问多少下切完

思路

明显,若m<n,尽量优先沿着n的方向切,使得最后需要一个个切的时候长边最短,(m - 1) * n + (n - 1)

代码

感想:

虽然是水题但是错了好几次甚至超时了。

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;

int main() {
#ifdef LOCAL_DEBUG
    freopen("C:\Users\Iris\source\repos\ACM\ACM\input.txt", "r", stdin);
    //freopen("C:\Users\Iris\source\repos\ACM\ACM\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
    int T;
    int m, n;
    for (int ti = 1;cin>>m>>n; ti++) {
        if (m > n)swap(m, n);
        cout << (m - 1) * n + (n - 1) << endl;
    }

    return 0;
}
View Code
原文地址:https://www.cnblogs.com/xuesu/p/10462972.html