• 【luogu P1514 引水入城】 题解


    题目链接:https://www.luogu.org/problemnew/show/P1514

     1 // luogu-judger-enable-o2
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 #define maxn 520
     7 #define inf 2147483647
     8 using namespace std;
     9 int n, m, cnt = 0, cur1 = 0, flag, ma[maxn][maxn], vis[maxn][maxn] = {0}, q[maxn];
    10 struct cover
    11 {
    12     int l,r;
    13 }c[maxn];
    14 int cmp(cover a, cover b)
    15 {
    16     if(a.l != b.l)
    17     return a.l < b.l;
    18     else return a.r > b.r;
    19 }
    20 void dfs(int x, int y, int now)
    21 {
    22     vis[x][y] = 1;
    23     if(x == n)
    24     {
    25         q[y] = 1;
    26         c[now].l = min(c[now].l , y);
    27         c[now].r = max(c[now].r , y);
    28     }
    29 
    30     if(ma[x+1][y] < ma[x][y] && x+1 <= n && vis[x+1][y] == 0) dfs(x+1,y,now);
    31 
    32     if(ma[x-1][y] < ma[x][y] && x-1 >= 1 && vis[x-1][y] == 0) dfs(x-1,y,now); 
    33 
    34     if(ma[x][y+1] < ma[x][y] && y+1 <= m && vis[x][y+1] == 0) dfs(x,y+1,now);
    35 
    36     if(ma[x][y-1] < ma[x][y] && y-1 >= 1 && vis[x][y-1] == 0) dfs(x,y-1,now);  
    37 }
    38 int main()
    39 {
    40     scanf("%d%d",&n,&m);
    41     for(int i = 1; i <= m; i++) 
    42     c[i].l = inf;
    43 
    44     for(int i = 1; i <= n; i++)
    45     for(int j = 1; j <= m; j++)
    46     {
    47         scanf("%d",&ma[i][j]);
    48     }
    49 
    50     for(int i = 1; i <= m; i++)
    51     {
    52         if(ma[1][i]>=ma[1][i-1])
    53         dfs(1,i,i);
    54         memset(vis,0,sizeof(vis));
    55     }
    56 
    57     for(int i=1;i<=m;i++)
    58     {
    59         if(q[i] == 0)
    60         flag++;
    61         //cout<<q[i]<<" ";
    62     }
    63    
    64     sort(c+1,c+1+m,cmp);
    65     
    66     if(flag != 0)
    67     printf("0
    %d",flag);
    68     else
    69     {
    70         int cur = c[1].r;
    71         cnt++;
    72         for(int i = cur; i <= m; i = cur1)
    73         {
    74             if(i == m)
    75             break;
    76             
    77             cnt++;
    78             
    79             for(int j = 1; c[j].l <= i+1; j++)
    80             cur1 = max(cur1, c[j].r);
    81         }
    82         printf("1
    %d",cnt);
    83     }
    84     return 0;
    85 }

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    ansible 通过堡垒机/跳板机 访问目标机器需求实战(ssh agent forward)
    运维标准化与流程化建设
    运维与自动化运维发展方向
    文件atime未变问题的研究
    ansible 任务委派 delegate_to
    ansible 调优
    windows中安装模拟器后修改模拟器中的hosts方法
    负载均衡服务器主要考量三个指标
    DRBD+NFS+Keepalived高可用环境
    sshpass
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/8798396.html
Copyright © 2020-2023  润新知