山东省第三届ACM大学生程序设计竞赛 The Best Seat in ACM Contest

就是把给出一个表,每个表的每个位置的价值就是和他相邻的位置的价值减去他的价值。如果一个位置没有相邻的,就减1;

输出最大的价值,有相同的就输出最大的行和列

#include <stdio.h>
#include <vector>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int value[25][25];
int dir[4][2]={0,1,0,-1,1,0,-1,0};
int main()
{
int t,case1=0;
scanf("%d",&t);
while(t--)
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        scanf("%d",&value[i][j]);
    int max1=-10000000;
    int x,y;
    x=y=0;
    printf("Case %d: ",++case1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            int cnt=0;
            int x1,y1;
            for(int k=0;k<4;k++)
            {
            x1=i+dir[k][0];
            y1=j+dir[k][1];
            if(x1<1||x1>n||y1<1||y1>m)cnt--;
            else cnt+=(value[x1][y1]-value[i][j]);
            }
            
            if(max1<=cnt)
            {
                max1=cnt;
                x=i;
                y=j;
            }
        }
        printf("%d %d %d\n",max1,x,y);
}
    return 0;
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值