当前位置:网站首页>Water diversion into chengluo Valley p1514
Water diversion into chengluo Valley p1514
2022-04-23 02:31:00 【Midnight】
subject
A big man's blog
Code
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef pair<int,int> PII;
bool vis[maxn][maxn];
int a[maxn][maxn];
int l[maxn],r[maxn];
int n,m;
int dx[4]={
0,0,-1,1};
int dy[4]={
-1,1,0,0};
queue<PII>q;
struct node
{
int l,r;
void clear()
{
l=inf;
}
}nd[maxn];
inline void bfs(int x,int y)
{
memset(vis,false,sizeof(vis));
q.push({
x,y});
while(!q.empty())
{
PII temp=q.front();
q.pop();
int x1=temp.first;
int y1=temp.second;
if(x1<1||x1>n||y1<1||y>m)
continue;
if(vis[x1][y1])
continue;
vis[x1][y1]=true;
if(x1==1)
{
nd[y].l=min(nd[y].l,y1);
nd[y].r=max(nd[y].r,y1);
}
for(int i=0;i<4;i++)
{
int kx=x1+dx[i];
int ky=y1+dy[i];
if(a[kx][ky]>a[x1][y1])
q.push({
kx,ky});
}
}
}
bool cmp(node a,node b)
{
if(a.l==b.l)
return a.r<b.r;
return a.l<b.l;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
int tot=0;
for(int i=1;i<=m;i++)
{
nd[i].clear();
bfs(n,i);
if(nd[i].l==inf)
tot++;
}
if(tot)
{
if(n!=1)
cout<<0<<endl<<tot;
else
cout<<1<<endl<<tot;
return 0;
}
sort(nd+1,nd+1+m,cmp);
int last=0;// Record the location of the last water station
for(int i=1;i<=m;i++)// Enumerate each place from the last line
{
if(last>=nd[i].l&&last<=nd[i].r)// If the last water station , In the area where water can be poured into this place
continue;
tot++;
last=nd[i].r;
}
cout<<1<<endl<<tot;
}
版权声明
本文为[Midnight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220826428617.html
边栏推荐
- 小程序 读取文件
- 006_ redis_ Sortedset type
- Startup of openstack service
- Yes, from today on, our fans can participate in Netease data analysis training camp for free!
- openstack 服务的启动
- C语言中*与&的用法与区别 以及关键字static和volatile 的含义
- Parental delegation model [understanding]
- 007_ Redis_ Jedis connection pool
- How to recognize products from the perspective of Dialectics
- Heap overflow of kernel PWN basic tutorial
猜你喜欢
电源电路设计原来是这么回事
Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
Daily question (April 22, 2022) - rotation function
[untitled]
Jupyter for local and remote access to ECS
小程序 canvas 画布半圆环
A domestic image segmentation project is heavy and open source!
How many steps are there from open source enthusiasts to Apache directors?
Real math problems in 1958 college entrance examination
How does Axure set the content of the text box to the current date when the page is loaded
随机推荐
小程序 读取文件
php 2022年4月20面试题整理
本地远程访问云服务器的jupyter
打靶narak
009_ Redis_ Getting started with redistemplate
十六、异常检测
go语言打怪通关之 ⌈互斥锁和状态协程⌋
Flink real-time data warehouse project - Design and implementation of DWS layer
So library dependency
How to prevent leakage of operation and maintenance data
Day18 -- stack queue
Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
011_ Redistemplate operation hash
Applet reads files
【无标题】
002_Redis_String类型常见的操作命令
Real math problems in 1958 college entrance examination
Leetcode46 Full Permutation
MySQL JDBC编程
IAR嵌入式開發STM32f103c8t6之點亮LED燈