HDU 4500 小Q系列故事——屌丝的逆袭(水题)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4500

思路:简单模拟

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long ll;
const int maxn = 40000;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int a[30][30];
int b[30][30];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m))
    {
        if(n + m == 0)
            break;
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(a[i][j] < 0)
                    b[i][j] = a[i-1][j] + a[i][j-1] + a[i][j+1] + a[i+1][j];
                else
                    b[i][j] = -(a[i-1][j] + a[i][j-1] + a[i][j+1] + a[i+1][j]);
            }
        }
        int row,column,max1 = -200;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(b[i][j] > max1)
                {
                    max1 = b[i][j];
                    row = i;
                    column = j;
                }
            }
        }
        printf("%d %d %d\n",row,column,max1);
    }
    return 0;
}


你可能感兴趣的:(HDU 4500 小Q系列故事——屌丝的逆袭(水题))