当前位置:网站首页>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
边栏推荐
- 小程序 canvas 画布半圆环
- 009_ Redis_ Getting started with redistemplate
- 打靶narak
- 007_Redis_Jedis连接池
- SO库依赖问题
- They are all intelligent in the whole house. What's the difference between aqara and homekit?
- 001_ Redis set survival time
- [assembly language] understand "stack" from the lowest point of view
- Halo open source project learning (I): project launch
- Numerical remapping method (remap)
猜你喜欢

Network jitter tool clumsy

Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
![[assembly language] understand](/img/73/2483bca93714e378ff5eef18bddcd1.jpg)
[assembly language] understand "stack" from the lowest point of view

RT_ Thread ask and answer

013_基于Session实现短信验证码登录流程分析

001_redis设置存活时间

Heap overflow of kernel PWN basic tutorial

Web learning record (medium)

If 404 page is like this | daily anecdotes

想体验HomeKit智能家居?不如来看看这款智能生态
随机推荐
Leetcode40 - total number of combinations II
OJ daily practice - Finish
010_StringRedisTemplate
程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
本地远程访问云服务器的jupyter
013_基于Session实现短信验证码登录流程分析
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
使用Go语言构建Web服务器
After idea is successfully connected to H2 database, there are no sub files
tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
If you want to learn SQL with a Mac, you should give yourself a good reason to buy a Mac and listen to your opinions
LeetCode 283. Move zero (simple, array) Day12
Consider defining a bean of type 'com netflix. discovery. AbstractDiscoveryClientOptionalArgs‘
Fast and robust multi person 3D pose estimation from multiple views
Data warehouse construction table 111111
Leetcode46 Full Permutation
Go语言web中间件的使用
Heap overflow of kernel PWN basic tutorial
双亲委派模型【理解】
007_Redis_Jedis连接池