当前位置: 首页 > wzjs >正文

网站游戏下载免费高清logo在线

网站游戏下载,免费高清logo在线,做网站提成,如何说服客户做网站[POI2007] GRZ-Ridges and Valleys 题面翻译 题目描述 译自 POI 2007 Stage 2. Day 0「Ridges and Valleys」 给定一个 n n n \times n nn 的网格状地图,每个方格 ( i , j ) (i,j) (i,j) 有一个高度 w i j w_{ij} wij​。如果两个方格有公共顶点&#xff0c…

[POI2007] GRZ-Ridges and Valleys

题面翻译

题目描述

译自 POI 2007 Stage 2. Day 0「Ridges and Valleys」

给定一个 n × n n \times n n×n 的网格状地图,每个方格 ( i , j ) (i,j) (i,j) 有一个高度 w i j w_{ij} wij。如果两个方格有公共顶点,则它们是相邻的。

定义山峰和山谷如下:

  • 均由地图上的一个连通块组成;
  • 所有方格高度都相同;
  • 周围的方格(即不属于山峰或山谷但与山峰或山谷相邻的格子)高度均大于山谷的高度,或小于山峰的高度。

求地图内山峰和山谷的数量。特别地,如果整个地图方格的高度均相同,则整个地图既是一个山谷,也是一个山峰。

输入格式

第一行一个整数 n n n 2 ≤ n ≤ 1000 2 \le n \le 1000 2n1000),表示地图的大小。

接下来 n n n 行每行 n n n 个整数表示地图。第 i i i 行有 n n n 个整数 w i 1 , w i 2 , … , w i n ( 0 ≤ w i j ≤ 1 000 000 000 ) w_{i1}, w_{i2}, \ldots, w_{in} (0 \le w_{ij} \le 1\ 000\ 000\ 000) wi1,wi2,,win(0wij1 000 000 000),表示地图第 i i i 行格子的高度。

输出格式

输出一行两个整数,分别表示山峰和山谷的数量。

样例解释

翻译来自于 LibreOJ。

题目描述

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 × n n\times n n×n square. For each field ( i , j ) (i,j) (i,j) belonging to the square(for i , j ∈ { 1 , ⋯ , n } i,j\in \{1,\cdots,n\} i,j{1,,n}), its height w ( i , j ) 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) (i,j) is adjacent to the fields ( i − 1 , j − 1 ) (i-1,j-1) (i1,j1), ( i − 1 , j ) (i-1,j) (i1,j), ( i − 1 , j + 1 ) (i-1,j+1) (i1,j+1), ( i , j − 1 ) (i,j-1) (i,j1), ( i , j + 1 ) (i,j+1) (i,j+1), ( i + 1 , j − 1 ) (i+1,j-1) (i+1,j1), ( i + 1 , j ) (i+1,j) (i+1,j), ( i + 1 , j + 1 ) (i+1,j+1) (i+1,j+1), provided that these fields are on the map).

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

all the fields in S S S have the same height,the set S S S forms a connected part of the map (i.e. from any field in S S S it is possible to reach any other field in S S S while moving only between adjacent fields and without leaving the set S S S),if s ∈ S s\in S sS and the field s ′ ∉ S s'\notin S s/S is adjacent to s s s, then w s > w s ′ w_s>w_{s'} ws>ws(for a ridge) or w s < w s ′ 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 n n n ( 2 ≤ n ≤ 1 000 2\le n\le 1\ 000 2n1 000)denoting the size of the map. Ineach of the following n n n lines there is the description of the successive row of the map. In ( i + 1 ) (i+1) (i+1)'th line(for i ∈ { 1 , ⋯ , n } i\in \{1,\cdots,n\} i{1,,n}) there are n n n integers w ( i , 1 ) , ⋯ , w ( i , n ) w_{(i,1)},\cdots,w_{(i,n)} w(i,1),,w(i,n)( 0 ≤ w i ≤ 1 000 000 000 0\le w_i\le 1\ 000\ 000\ 000 0wi1 000 000 000), separated by single spaces. Thesedenote the heights of the successive fields of the i i i’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

样例输入 #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

样例 #2

样例输入 #2

5
5 7 8 3 1
5 5 7 6 6
6 6 6 2 8
5 7 2 5 8
7 1 0 1 7

样例输出 #2

3 3

题解

#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+7;long long f[N][N];
int n, sf = 0, sg = 0;
int dx[] = {0, -1, -1, 0, 1, 1, 1, 0, -1}, dy[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};	//上右下左顺时针旋转 
bool vis[N][N], isf = false, isg = false; void dfs(int x,int y){vis[x][y] = 1; for(int i=1;i<=8;++i){int nx = x + dx[i], ny = y + dy[i];	 if(nx < 0 || nx >= n || ny < 0 || ny >= n) continue;if(f[nx][ny] == f[x][y]){if(vis[nx][ny]) continue;dfs(nx, ny);}else if(f[nx][ny] > f[x][y]) isg = true;//看来是山谷else if(f[nx][ny] < f[x][y]) isf = true;//山峰}//不用 vis[x][y] = 0;return ;
}int main(){cin>>n;for(int i=0;i<n;++i){for(int j=0;j<n;++j){cin>>f[i][j];}}for(int i=0;i<n;++i){for(int j=0;j<n;++j){isf = false;//初始化isg = false;if(!vis[i][j]){//没走过dfs(i, j);if(isf && !isg)	sf++;//只是山峰不是山谷else if(!isf && isg) sg++;//不是山峰只是山谷}}} if(sf == 0 && sg == 0) cout<<"1 1"<<endl;//特判 else cout<<sf<<" "<<sg<<endl;return 0;	
}
http://www.dtcms.com/wzjs/792582.html

相关文章:

  • 上海建设牌电动三轮官方网站wordpress huxiu
  • 网站 逻辑结构上海哪个区最繁华
  • 学风建设网站的优势建官网需要多少钱
  • 吴忠公司做网站南昌网站建设哪里好
  • 高端网站设计公司排名建设中学校园网站的来源
  • 厦门网站开发比较大的公司福田区住房和建设局官方网站
  • 免费建立网站平台教育资源网站建设
  • 怎样做百度推广网站空间购买网站
  • 网站被攻击会影响收录么亿网中国网站管理系统
  • 廊坊做网站找谁做网站的股哥
  • 网站建设季度考核评价工作总结wordpress文章显示失败
  • 柯桥区住房和城乡建设局网站权威解读当前经济热点问题
  • 网站建设阶段推广策略如何给网站做防盗链
  • wdcp 网站备份网络营销专业是学什么的
  • 用动物做网站名称电子商务网站建设 asp
  • 中国建设银行西平支行网站爬虫网站怎么做
  • 如何用flash做网站网站建设的基本要求
  • 双语网站费用如何编写代码
  • 凡科建的网站可以做seo吗贵阳app开发公司哪家强
  • 自己怎么开网站H5酒店静态网站建设开题报告范文
  • 指数 网站权重国内视频网站域名
  • 南阳网站制作公司宁波seo专员
  • 闵行网站推广台州seo网站推广费用
  • 搭建flv视频网站咨询网络服务商
  • 网站到期查询wordpress商品展示模板下载
  • 好的 做网站的软件公司苏州app开发定制
  • 大连模板网站制作推荐深圳品牌创意网站建设
  • 网站建设的网络公司wordpress淘口令插件
  • 网站群集建设建网站公司 优帮云
  • 网站建设通有的网站网速慢