Problem Description
Problem Analysis
First record the charm value of the person at each position
Then just compute them separately
Since we only need the maximum value
We only need to keep track of the maximum while computing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| #include<stdio.h>
#include<math.h>
int map[22][22];
int main() {
int n,m;
while(scanf("%d %d",&n,&m),n||m) {
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
scanf("%d",&map[i][j]);
int max=-999999,maxi,maxj;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
int sum=0;
if(i-1>=0) {
if(map[i][j]*map[i-1][j]>0)
sum-=abs(map[i-1][j]);
else
sum+=abs(map[i-1][j]);
}
if(i+1<n) {
if(map[i][j]*map[i+1][j]>0)
sum-=abs(map[i+1][j]);
else
sum+=abs(map[i+1][j]);
}
if(j-1>=0) {
if(map[i][j]*map[i][j-1]>0)
sum-=abs(map[i][j-1]);
else
sum+=abs(map[i][j-1]);
}
if(j+1<m) {
if(map[i][j]*map[i][j+1]>0)
sum-=abs(map[i][j+1]);
else
sum+=abs(map[i][j+1]);
}
if(sum>max) {
max=sum;
maxi=i;
maxj=j;
}
}
}
printf("%d %d %d\n",maxi+1,maxj+1,max);
}
return 0;
}
|
Problem link: HDU 4500 Little Q Series Story — The Loser’s Counterattack