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

祺越网站建设太原百度关键词优化

祺越网站建设,太原百度关键词优化,如何速发布wordpress,莱芜网络推广公司[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/595151.html

相关文章:

  • 小蚂蚁page页面模板阿里seo外包能去吗
  • 浦东新区建设工程安全质量监督站网站长尾关键词什么意思
  • 美食网站首页怎么做做网站支持提现支付宝
  • 视频网站建站费用苏州建网站制作费用多少钱
  • 网站二维码弹窗做网站要多少钱汉狮
  • php团购网站开发wordpress站群教程
  • 更改网站主题怎么分析网站设计
  • 网页设计架构山东关键词优化推广
  • 湖南网站设计公司如何在手机上制作游戏
  • 中学网站建设方案设计官网收费标准
  • 深圳优化网站wordpress 完整搬家
  • 湖北网站设计流程深圳 网站建设培训班
  • 简速做网站青岛如何做网站seo
  • 建设部网站查资质6WordPress验证问题
  • 农产品如何建设网站网站建设厌倦
  • 网站建设收费流程网站建设哪里招标
  • 河南住房和城乡建设厅网站抄袭网站模板
  • 提供网站建设课程报告沈阳制作公司网站和app
  • 上杭县铁路建设办公室网站网络系统管理属于什么专业类别
  • 兰州网站推广优化教你如何创建自己的网站
  • 微网站是什么意思手机网站单页面
  • 怎么免费申请网站图片设计与制作软件下载
  • 周至做网站国外域名。国内网站
  • 做网站的相关教程新主题wordpress
  • 潍坊网络建站模板长链接变短链接在线生成
  • 做甜品的网站国外免费建站网站
  • 大连网站建设培训静态网站建设背景
  • 网站搭建的流程是什么做简单网站需要学什么软件
  • 简述网站推广的五要素wordpress 千万数据库
  • 网站开发公司盈利重庆建网站方法