首页 技术 正文
技术 2022年11月15日
0 收藏 304 点赞 2,265 浏览 1195 个字

传送门

NOIP的题目都难以写精简题意


考虑最上面一排的某一个点对最下面一排的影响是什么样的,不难发现必须要是一段连续区间才能够符合题意。

如果不是一段连续区间,意味着中间某一段没有被覆盖的部分比周围都要高(因为当前这一个点的流域越过了这一段区间却又包含了其左右的一段区间,所以它的流域一定会包住这一个没有被流到的部分),这表示有一段区间是无论水源在哪里都无法流到的,所以就是无解了。

我们知道影响范围是一段区间之后,通过BFS把所有区间求出来,就是一个经典的线段覆盖问题了。贪心解决即可

 #include<bits/stdc++.h> using namespace std; ][] , x , y , dir[][] = {,,,-,,,-,}; ] , vis[][]; struct qj{     int l , r; }ans[]; bool cmp(qj a , qj b){return a.l < b.l;} inline int min(int a , int b){return a < b ? a : b;} inline int max(int a , int b){return a > b ? a : b;} int main(){     scanf("%d%d" , &x , &y);      ; i <= x ; i++)          ; j <= y ; j++)             scanf("%d" , &m[i][j]);      ; i <= y ; i++){         memset(vis ,  , sizeof(vis));         ans[i].l = ;    ans[i].r = -;          || m[][i] >= m[][i - ]) && (i == y || m[][i] >= m[][i + ])){             queue < pair < int , int > > q;             q.push(make_pair( , i));             while(!q.empty()){                 pair < int , int > t = q.front();                 q.pop();                 if(t.first == x){                     ans[i].l = min(ans[i].l , t.second);                     ans[i].r = max(ans[i].r , t.second);                     allVis[t.second] = ;                 }                  ; j <  ; j++)                     ] >  && t.first + dir[j][] <= x)                         ] >  && t.second + dir[j][] <= y)                             ]][t.second + dir[j][]])                                 ]][t.second + dir[j][]] < m[t.first][t.second]){                                     vis[t.first + dir[j][]][t.second + dir[j][]] = ;                                     q.push(make_pair(t.first + dir[j][] , t.second + dir[j][]));                                 }             }         }     }      ; i <= y ; i++)         if(!allVis[i]){             ;              ; j <= y ; j++)                 cnt += !allVis[j];             cout <<  << endl << cnt;             ;         }     sort(ans +  , ans + y +  , cmp);      , num =  , dir = ;     while(r <= y){         num++;         ;         );         r = newR;     }     cout <<  << endl << num;     ; }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848