省赛 Plumbing the depth of lake
2017-05-31 19:41
330 查看
时间限制: 1 Sec 内存限制: 128 MB
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.
* 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);
本题题意:
本题意思就是有一片池塘,池塘中有许多的小山谷,现在想知道池塘的深度。在N*M的矩阵中,0代表湖上的一个小岛。其余数字代表池塘的深度,如果其相邻的八个方向有相同的数字,则这个数为其池塘深度,现在要求能确定的池塘的最深深度。
解题思路:
用深搜,直接搜其八个方向,用数组存其能确定的最大深度,不断刷新数组,找出最大深度即可。
代码:
题目描述
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 hillsand 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
本题题意:
本题意思就是有一片池塘,池塘中有许多的小山谷,现在想知道池塘的深度。在N*M的矩阵中,0代表湖上的一个小岛。其余数字代表池塘的深度,如果其相邻的八个方向有相同的数字,则这个数为其池塘深度,现在要求能确定的池塘的最深深度。
解题思路:
用深搜,直接搜其八个方向,用数组存其能确定的最大深度,不断刷新数组,找出最大深度即可。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> using namespace std; int dx[8]={1,1,-1,-1,0,0,1,-1};///定义其八个方向 int dy[8]={0,1,0,-1,1,-1,-1,1};///定义其八个方向 int map[55][55]; int main() { int T,M,N,i,j,k; scanf("%d",&T); while(T--) { int maxx=-1; memset(map,-1,sizeof(map)); scanf("%d%d",&M,&N); 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++) { if(maxx>map[i][j]) continue; for(k=0; k<8; k++) { if(map[i][j]==map[i+dx[k]][j+dy[k]]) maxx=map[i][j]; } } } printf("%d\n",maxx); } }
相关文章推荐
- 问题 G: Plumbing the depth of lake
- 第十届ACM省赛-E Plumbing the depth of lake
- 河南省第十届ACM省赛G:Plumbing the depth of lake
- G Plumbing the depth of lake 河南第十届ACM真题 【搜索】
- 河南省第十届ACM省赛题目:问题 G: Plumbing the depth of lake
- 2017年河南省ACM省赛 Problem G: Plumbing the depth of lake
- 深入研究 STL Deque 容器-An In-Depth Study of the STL Deque Container (By Nitron)
- FWNX-creates a linked list of all the nodes at each depth-JAVA VERSION
- 深入研究 STL Deque 容器-An In-Depth Study of the STL Deque Container (By Nitron)
- The Phantom of the Opera-9、The house on the lake
- [CrackCode] 4.4 Creates a linked list of all the nodes at each depth of a given tree
- 【JS】There’s Nostalgia in the Waters of Lake.js
- Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
- java数据结构-二叉树-Compute the depth of a binary tree.
- [Leetcode] The minimum depth of binary tree二叉树的最小深度
- Write a function to find the depth of a binary tree
- Count the depth of the stack in JVM.
- Understand the boot-up procedure of Linux in Depth
- The first in-depth technical analysis of VP8
- Q 4.4 creates a linked list of all the nodes at each depth