题意翻译

给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的。若两个格子有公共顶点,那么他们就是相邻的格子。(所以与(i,j)相邻的格子有(i-1, j-1),(i-1,j),(i-1,j+1),(i,j-1),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1))。我们定义一个格子的集合S为山峰(山谷)当且仅当:

1.S的所有格子都有相同的高度。

2.S的所有格子都联通3.对于s属于S,与s相邻的s’不属于S。都有ws > ws’(山峰),或者ws < ws’(山谷)。

你的任务是,对于给定的地图,求出山峰和山谷的数量,如果所有格子都有相同的高度,那么整个地图即是山峰,又是山谷。

输入 第一行包含一个正整数n,表示地图的大小(1<=n<=1000)。接下来一个n*n的矩阵,表示地图上每个格子的高度。(0<=w<=1000000000)

输出 应包含两个数,分别表示山峰和山谷的数量。

感谢@Blizzard 提供的翻译

题目描述

Byteasar loves trekking in the hills. During the hikes he explores all the ridges and valleys in vicinity.

Therefore, in order to plan the journey and know how long it will last, he must know the number of ridgesand valleys in the area he is going to visit. And you are to help Byteasar.

Byteasar has provided you with a map of the area of his very next expedition. The map is in the shape ofa n\times nn×nsquare. For each field (i,j)(i,j) belonging to the square(for i,j\in \{1,\cdots,n\}i,j∈{1,⋯,n} ), its height w_{(i,j)}w(i,j)​ is given.

We say two fields are adjacent if they have a common side or a common vertex (i.e. the field (i,j)(i,j) is adjacent to the fields (i-1,j-1)(i−1,j−1) , (i-1,j)(i−1,j) , (i-1,j+1)(i−1,j+1) , (i,j-1)(i,j−1) , (i,j+1)(i,j+1) , (i+1,j-1)(i+1,j−1) , (i+1,j)(i+1,j) , (i+1,j+1)(i+1,j+1) , provided that these fields are on the map).

We say a set of fields SS forms a ridge (valley) if:

all the fields in SS have the same height,the set SS forms a connected part of the map (i.e. from any field in SS it is possible to reach any other field in SS while moving only between adjacent fields and without leaving the set SS ),if s\in Ss∈S and the field s'\notin Ss′∉S is adjacent to ss , then w_s>w_{s'}ws​>ws′​ (for a ridge) or w_s<w_{s'}ws​<ws′​ (for a valley).

In particular, if all the fields on the map have the same height, they form both a ridge and a valley.

Your task is to determine the number of ridges and valleys for the landscape described by the map.

TaskWrite a programme that:

reads from the standard input the description of the map, determines the number of ridges and valleys for the landscape described by this map, writes out the outcome to the standard output.

给定一张地势图,求山峰和山谷的数量

输入输出格式

输入格式:

In the first line of the standard input there is one integer nn ( 2\le n\le 1\ 0002≤n≤1 000 )denoting the size of the map. Ineach of the following nn lines there is the description of the successive row of the map. In (i+1)(i+1) 'th line(for i\in \{1,\cdots,n\}i∈{1,⋯,n} ) there are nn integers w_{(i,1)},\cdots,w_{(i,n)}w(i,1)​,⋯,w(i,n)​ ( 0\le w_i\le 1\ 000\ 000\ 0000≤wi​≤1 000 000 000 ), separated by single spaces. Thesedenote the heights of the successive fields of the ii 'th row of the map.

输出格式:

The first and only line of the standard output should contain two integers separated by a single space -thenumber of ridges followed by the number of valleys for the landscape described by the map.

输入输出样例

输入样例#1: 复制

5
8 8 8 7 7
7 7 8 8 7
7 7 7 7 7
7 8 8 7 8
7 8 8 8 8
输出样例#1: 复制

2 1
思路:水题,没看见上面两句话,炸了两次,gg;
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans,bns,flag,hg;
int map[][],vis[][];
void dfs(int x,int y,int col){
if(x<||x>n||y<||y>n) return ;
if(map[x][y]!=col&&map[x][y]>col&&flag==) flag++;
else if(map[x][y]!=col&&map[x][y]<col&&flag==) flag--;
else if(map[x][y]!=col&&map[x][y]>col&&flag<) hg=;
else if(map[x][y]!=col&&map[x][y]<col&&flag>) hg=;
if(map[x][y]!=col||vis[x][y]) return ;
vis[x][y]=;
dfs(x+,y,col);dfs(x-,y,col);dfs(x+,y+,col);dfs(x-,y-,col);
dfs(x,y+,col);dfs(x,y-,col);dfs(x+,y-,col);dfs(x-,y+,col);
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%d",&map[i][j]);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(!vis[i][j]){
flag=;hg=;
dfs(i,j,map[i][j]);
if(hg==&&flag<=) ans++;
if(hg==&&flag>=) bns++;
}
cout<<ans<<" "<<bns;
}
 

洛谷 P3456 [POI2007]GRZ-Ridges and Valleys的更多相关文章

  1. [洛谷P3460] [POI2007]TET-Tetris Attack

    洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...

  2. [洛谷3457][POI2007]POW-The Flood

    洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...

  3. 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)

    洛谷题目传送门 正解是树状数组维护dfn序上的前缀和,这样的思路真是又玄学又令我惊叹( 我太弱啦,根本想不到)Orz各路Dalao 今天考了这道题,数据范围还比洛谷的小,只有\(10^5\)(害我复制 ...

  4. 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]

    题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...

  5. 洛谷 P3462 [POI2007]ODW-Weights

    题面: https://www.luogu.org/problemnew/show/P3462 https://www.lydsy.com/JudgeOnline/problem.php?id=111 ...

  6. 题解【洛谷P3456】[POI2007]GRZ-Ridges and Valleys

    题面 考虑 \(\text{Flood Fill}\). 每次在 \(\text{BFS}\) 扩展的过程中增加几个判断条件,记录山峰和山谷的个数即可. #include <bits/stdc+ ...

  7. 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)

    题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...

  8. 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]

    [POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...

  9. 【刷题】洛谷 P3455 [POI2007]ZAP-Queries

    题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...

随机推荐

  1. 微信小程序button授权页面,用户拒绝后仍可再次授权

    微信小程序授权页面,进入小程序如果没授权跳转到授权页面,授权后跳转到首页,如果用户点拒绝下次进入小程序还是能跳转到授权页面,授权页面如下 app.js  中的 onLaunch或onShow中加如下代 ...

  2. spark shuffle:分区原理及相关的疑问

    一.分区原理 1.为什么要分区?(这个借用别人的一段话来阐述.) 为了减少网络传输,需要增加cpu计算负载.数据分区,在分布式集群里,网络通信的代价很大,减少网络传输可以极大提升性能.mapreduc ...

  3. InChatter系统之本地化

    InChatter现在支持本地化了,其实这个只是很细节的东西,但是咱也是可以走走国际范.哈哈 其实最重要的原因只是想进行一次本地化的开发.这个概念相信大部分人都有,但是在实际项目中真的很少会涉及到,我 ...

  4. 一台机器运行多个JBoss多实例

    JBossXMLJVMTomcat应用服务器  我们经常会遇到这种情况,有时候希望在同一台机器上部署若干个JBoss实例,上面运行不同的应用程序,这样的话无论由于什么原因需要对某个JBoss实例进行关 ...

  5. OpenCV3.3安装教程

    http://blog.csdn.net/amusi1994/article/details/76768775?locationNum=10&fps=1

  6. 【原创】webbluetoorh 在windows下无法显示搜索列表,在mac下正常的解决办法

    google webbluetooth在windows下不能弹出设备搜索列表提示“Web Bluetooth API is not available”,因为webbluetooth是google新推 ...

  7. html 零散问题

    1.iconfont的使用 https://www.cnblogs.com/yujihang/p/6706056.html 2.阴影效果比较 box-shadow:0 0 6px #000 inset ...

  8. windows测试物理网络

    ping 192.168.10.88 -t ,参数-t是等待用户去中断测试 

  9. JAVA基础——内存流

    掌握内存操作流 输入和输出都是从文件中来的,当然,也可将输出的位置设置在内存上,这就需要ByteArrayInputStream和ByteArrayOutputStream ByteArrayInpu ...

  10. 学习 Qt 编程的好书精品推荐!

    最近一段时间,准备开始搞Qt方面的东西,想找几本书看看.网上介绍QT的书籍也有很多,不想浪费时间,所以想找几本精品的书籍来看.花了半天的时间找了几本非常不错的,这里面整理好之后推荐给大家! 下面介绍的 ...