zoukankan      html  css  js  c++  java
  • P2004 领地选择

    题目读完首先想到读入时前缀和处理一下,然后枚举首都左上角坐标即可,数据很弱所以可以通过,事实证明我的思路是对的.

    为了保险还给ans开了个long long,燃鹅我还是年轻.

     最后一个点还是把我卡爆了,原因竟然是题目没有提及的地块上的价值的数据范围.

    数组开long long,搞定了.

    有点水.

    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    int n, m, c;
    long long s[1010][1010];
    long long ans = -100000000;
    int x, y;
    
    int main() {
    //    freopen("in.txt", "r", stdin);
        cin >> n >> m >> c;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) {
                cin >> s[i][j];
                s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
            }
    
        for (int i = 1; i + c - 1 <= n; i++)
            for (int j = 1; j + c - 1 <= m; j++) {
                long long val = (long long)s[i + c - 1][j + c - 1] - s[i - 1][j + c - 1] - s[i + c - 1][j - 1] + s[i - 1][j - 1];
                if (ans < val){
                    x = i;
                    y = j;
                    ans = val;
                }
            }
        cout << x << ' ' << y << endl;
    
        return 0;
    }
    View Code
  • 相关阅读:
    python_函数
    初始python第三天(三)
    python入门练习题2
    python开发进阶之路(一)
    python入门练习题1
    初识Python第三天(二)
    初识Python第三天(一)
    初识Python第二天(4)
    初识python第二天(3)
    c windows控制台输出颜色文字
  • 原文地址:https://www.cnblogs.com/Gaomez/p/14162496.html
Copyright © 2011-2022 走看看