title: Plumbing the depth of lake 河南省第十届省赛

题目描述:

There is a mysterious lake in the north of Tibet. As the sun shines, the surface of the lake is colorful and colorful. The lake was unfathomable in rainy weather.  After the probe,  It has an interesting bottom in that it is full of little hills and valleys. .** **Scientists wonders how deep the bottom of the lake is.

Scientists use the most advanced radar equipment to detect the bottom of the lake. It is the discovery that the deepest part is relatively flat. Thet want to know the largest depth number only if it is verified by the fact that the same depth appears in an adjacent reading.

To facilitate computing, scientists have put the lake as M * N grids .*The depth  reading of each grid is already known. some readings might be 0-- It's a small island on the lake.

Find the greatest depth that appears in at least two 'adjacent'readings (where 'adjacent' means in any of the potentially eight squares that border a square on each of its sides and its diagonals). The lake has at least one pair of positive, adjacent readings.

输入:

The first line of the input contains one integers T, which is the nember of  test cases (1<=T<=5).  Each test case specifies:

  • Line 1:      Two space-separated integers: M and N   (1 ≤ M,  N ≤ 50)

  • Lines 2..M+1: Line i+1 contains N space-separated integers that  represent the depth of the lake across row i: Dij    (0 <= Dij <=1,000,000);

输出:

For each test case generate a single line:  a single integer that is the depth of the lake determined.

样例输入:

1
4 3
0 1 0
1 2 0
1 5 1
2 3 4

样例输出:

1

分析:

找出湖底的只要有两个单位面积相连(八个方向)的最大的深度,跟这个深度面积的大小没有关系。

代码:

#include <cstdio>
#include <cstring>
int Map[55][55];
int dx[8] = {-1,-1,-1,0,0,1,1,1};
int dy[8] = {-1,0,1,-1,1,-1,0,1};
int Max;
void Search(int i,int j)
{
int k;
if(Map[i][j]==-1) return ; if(Max >= Map[i][j]) return ;///找出深度最大的 for(k=0; k<8; k++)
{
if(Map[i][j] == Map[i + dx[k]] [j + dy[k]]) ///八个方向找一下,只要有一个就行,有就更新 Max
{
Max = Map[i][j];
break;
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
Max = -1;
int i,j,m,n;
scanf("%d%d",&m,&n);
memset(Map,-1,sizeof(Map));
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
scanf("%d",&Map[i][j]);
}
}
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
Search(i,j);
}
}
printf("%d\n",Max);
}
return 0;
}

最新文章

  1. .NET跨平台之旅:数据库连接字符串写法引发的问题
  2. Daily Scrum Meeting ——SecondDay
  3. docker安装
  4. IOS 网络浅析-(八 NSURLSession简介)
  5. 非常非常非常好!path-sum-iii
  6. c#调用命令行遇到带空格的路径
  7. POJ 3692 最大独立集
  8. 20160331javaweb之JSP include 指令&amp;&amp;九大隐式对象
  9. QTP中FSO的使用
  10. Glide 这样用,更省内存!!!
  11. Jquery.Uploadify实现批量上传显示进度条 取消 上传后缩略图显示 可删除
  12. [LeetCode] Minimize Max Distance to Gas Station 最小化去加油站的最大距离
  13. html页面的CSS、DIV命名规则(仅供参考学习)
  14. Confluence 6 复杂授权或性能问题
  15. 异常:Keyword not supported: &#39;data source&#39;的解决办法
  16. PHP(层叠样式表,写法分类),选择器的种类)
  17. Flutter学习之路---------第一个Flutter项目
  18. git-02 下载代码
  19. NOIP赛前集训营-提高组(第一场)#B 数数字
  20. OpenCV学习笔记 - Video Analysis - 录制视频

热门文章

  1. 【WPF】 布局篇
  2. CDateTimeUI类源码分析
  3. Qt Qwdget 汽车仪表知识点拆解3 进度条编写
  4. 虚拟现实-VR-UE4-LEAP-Motion手势识别
  5. 自动化测试--testNG
  6. Oracle数据库抽数神器toad
  7. [转载] python 解析xml 文件: SAX方式
  8. redis基础和通用key操作
  9. 并查集——poj1611(入门)
  10. NO1——线段树