版权声明:本人原创文章若需转载请标明出处和作者!沙沙 https://blog.csdn.net/weixin_44143702/article/details/86526815
爬山
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
LeiQ最近参加了一个登山俱乐部,部长给他了一个n*m地图,地图上的每一个格子的值表示一个山的海拔高度,LeiQ现在在(x,y)表示在地图上的位置,他想要登上地图上最高的山,所以他想知道他爬上最高的山的山顶还需向上爬多少米。
例如:
x\y |
1 |
2 |
3 |
1 |
100 |
130 |
150 |
2 |
200 |
300 |
100 |
3 |
100 |
150 |
50 |
现在LeiQ在(2,1),则他的位置海拔高度为200米,最高的为300米,所以还需爬100米
Input
多组输入
每组的第一行是两个整数n,m(1<=n,m<=100),表示地图的大小
接下来n行,每行m个整数,表示山的海拔高度(0<=Hij<=1000)
最后一行两个整数x,y表示LeiQ的位置
Output
输出他还需要向上爬多少米。
Sample Input
3 3 100 130 150 200 300 100 100 150 50 2 1
Sample Output
100
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
int n, m, i, j, x, y;
int h[101][101];
while(~scanf("%d %d", &n, &m))
{//记得多组输入!!!
memset(h, 0, sizeof(h));
for(i = 1; i <= n; i++)
{
//LeiQ的位置是从1开始的,不要从0开始存海拔!!!
for(j = 1; j <= m; j++)
{
scanf("%d", &h[i][j]);
}
}
int max = h[1][1];
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
if(max < h[i][j]) max = h[i][j];
}//求出最高海拔max
}
scanf("%d %d", &x, &y);
int sum = 0;
sum = max - h[x][y];//还需向上爬 max - LeiQ所在高度 = sum
printf("%d\n", sum);
}
return 0;
}