题解 | #小美的蛋糕切割#

小美的蛋糕切割

https://www.nowcoder.com/practice/15aa2c407c8840e09e2532313fb6809d

十年OI一场空,不开long long 见祖宗。

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
const ll N = 1e3 + 5, mod = 1e9 + 7, inf = 2e18;

int n, m, q;
ll a[N][N];

void solve() {
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        }
    }

    //遍历行
    ll ans = inf;
    for (int i = 1; i < m; i++) {
        ll x = a[n][i];
        ll y = a[n][m] - x;
        ans = min(ans, abs(x - y));
    }

    for (int i = 1; i < n; i++) {
        ll x = a[i][m];
        ll y = a[n][m] - x;
        ans = min(ans, abs(x - y));
    }

    cout << (ans == inf ? a[1][1] : ans);

}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {

        solve();

    }

    return 0;
}

全部评论

相关推荐

08-08 11:34
深圳大学 C++
点赞 评论 收藏
分享
08-12 07:02
中南大学 C++
您所拨打的号码无法接...:之前的经验是:鹅首先会根据你的意向放在意向部门池子里捞,如果没捞则进入大池子。能够快速捞起的最好方法就是每天刷新简历,不停刷直到有面试邀约为止。
投递腾讯等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务