就是把给出一个表,每个表的每个位置的价值就是和他相邻的位置的价值减去他的价值。如果一个位置没有相邻的,就减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;
}