hdu 4500 小Q系列故事——屌丝的逆袭

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>

using namespace std;

const int MAXN  = 25;

int fabs(int a)
{
    return a > 0 ? a : (-a);
}

int Find_Abs(int a, int b)
{
    if(a * b < 0)
        return fabs(b);
    else if(a * b > 0)
        return -fabs(b);
    else
        return 0;
}

int main()
{
    int Graph[MAXN][MAXN];
    int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
    int CurVal;
    int i, j, k, xpos, ypos;
    int MaxNum;
    int row, col;
    while(scanf("%d%d", &row, &col) && (row + col))
    {
        memset(Graph, 0, sizeof(Graph));
        for(i = 1; i <= row; ++i)
            for(j = 1; j <= col; ++j)
                scanf("%d", &Graph[i][j]);

        MaxNum = INT_MIN , xpos = 1, ypos = 1;

        for(i = 1; i <= row; ++i)
        {
            for(j = 1; j <= col; ++j)
            {
                CurVal = 0;
                for(k = 0; k < 4; ++k)
                {
                    int x = i + dir[k][0];
                    int y = j + dir[k][1];
                    if(x < 1 || x > row || y < 1 || y > col)
                        continue ;
                    CurVal += Find_Abs(Graph[i][j], Graph[x][y]);
                }
                if(CurVal > MaxNum)
                {
                    MaxNum = CurVal;
                    xpos = i, ypos = j;
                }
            }
        }
        printf("%d %d %d\n", xpos, ypos, MaxNum);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值