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;
}

河南省第十届省赛 Plumbing the depth of lake (模拟)的更多相关文章

  1. 河南省第十届省赛 Intelligent Parking Building

    title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...

  2. 河南省第十届省赛 Binary to Prime

    题目描述: To facilitate the analysis of  a DNA sequence,  a DNA sequence is represented by a binary  num ...

  3. 四川第十届省赛 A.Angel Beats bitset

    四川第十届省赛 A.Angel Beats bitset 题目链接 题解参考:http://www.cnblogs.com/Aragaki/p/9142250.html 考虑用bitset来维护对于所 ...

  4. 每天一套题打卡|河南省第十届ACM/ICPC

    A.谍报分析 题意:请你编程,快速统计出频率高的前十个单词. 思路:字符串输入,map哈希表map<string,int >记录每个单词出现的次数,pair重载优先级 #include&l ...

  5. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  6. 【河南省第十届ACM 省赛 A-谍报分析】

    题目描述 “八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战.但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行. 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动 ...

  7. CSU 1511 残缺的棋盘 第十届湖南省赛题

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...

  8. CSU 1507 超大型LED显示屏 第十届湖南省赛题

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507 解题思路:这是一道模拟题,看了那么多人的代码,我觉得我的代码是最简的,哈哈,其实就 ...

  9. 福州大学第十届校赛 & fzu 2128最长子串

    思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...

随机推荐

  1. redis学习资料汇总

    redis学习资料汇总 2017年01月07日 22:10:37 阅读数:281 转载:http://blog.csdn.net/wtyvhreal/article/details/50427627 ...

  2. 【数据库】 SQLite 语法

    [数据库] SQLite 语法 一 . 创建数据库 1. 只需创建数据库,只需创建文件,操作时将连接字符串指向该文件即可 2. 连接字符串 : data source = FilePath; 不能加密 ...

  3. static和final的区别(转载)

    Java中static 和final的区别 final定义的变量可以看做一个常量,不能被改变: final定义的方法不能被覆盖: final定义的类不能被继承. final static 就是再加上s ...

  4. springmvc基础篇—使用注解方式为前台提供数据

    一.新建一个Controller package cn.cfs.springmvc.service; import java.util.ArrayList; import java.util.Hash ...

  5. 常见bug解析-移动端

    手机测试常见bug解析 1.测试时遇到“手机无响应”? 有以下几个原因: a.手机内存不足 b.android进程之间死锁引起的(就是两个进程之间) c.手机的CPU运行高引起的 可以查看手机的崩溃日 ...

  6. DFS(1)——hdu1518Square

    一.题目回顾 题目链接:Square 题意:给你M根木棒,请判断这些木棒能否组成正方形. 二.解题思路 DFS+剪枝 [变量说明] sum:木棒的总长度 ave:形成的正方形的边长 maxlen:最长 ...

  7. JavaSE复习(四)File类与IO流

    File类 构造方法 public File(String pathname) :通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例. public File(String parent ...

  8. hbase1.2.6完全分布式安装

    环境,参考之前的两篇博文: jdk1.7 hadoop2.6.0 完全分布式 一个master,slave1,slave2,slave3 zookeeper3.4.6 完全分布式 安装与配置:(以下步 ...

  9. [转] const int *a与int *const a,const int *const a的区别

    http://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰的位置在 ...

  10. 【linux】亲测成功_CentOS7.2/rhel7.2 忘记root密码及重置root密码的方法?

    本文转自:https://www.jb51.net/article/146320.htm  CentOS 7 root密码的重置方式和CentOS 6完全不一样,以进入单用户模式修改root密码为例. ...