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
Hint
Source
**本题最主要的是找最大值,为了提到程序的运行效率,可在输入数据时一起比较寻找最大值
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m;
int a1,a2;
int a[100][100];
int i,j;
while(~scanf("%d%d",&n,&m)) //多组输入指导文本结束
{
int max=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]); //输入海拔数据
if(a[i][j]>max) //比较大小找出最大值
{
max=a[i][j];
}
}
}
scanf("%d%d",&a1,&a2);
printf("%d\n",max-a[a1-1][a2-1]); //注意输入的坐标a1,a2为从1开始的所以下标为a1-1和a2-1;
}
return 0;
}
运行结果:
3 3
100 130 150
200 300 100
100 150 50
2 1
100
^Z
Process returned 0 (0x0) execution time : 30.241 s
Press any key to continue.