zoukankan      html  css  js  c++  java
  • AT2043 [AGC004C] AND Grid 题解

    Description

    Luogu传送门

    Solution

    非常巧妙的构造题。

    考虑先构造出不相交的矩阵,就是相当于两只手交叉的两个矩阵。

    如下图:

    image

    然后再把输入的字符矩阵中是 # 的位置在两个矩阵中都赋值为 #,就能做到四联通且恰好覆盖了。

    Code

    (附上丑陋的代码,懒得改了。)

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 510;
    int n, m;
    char s[N][N], a[N][N], b[N][N];
    
    int main(){
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; ++i){
            scanf("%s", s[i] + 1);
            for(int j = 1; j <= m; ++j)
                a[i][j] = b[i][j] = s[i][j];
        }
        for(int i = 1; i <= n; ++i)
            a[i][1] = b[i][m] = '#';
        for(int i = 1; i <= n; i += 2)
            for(int j = 2; j < m; ++j)
                a[i][j] = b[i + 1][j] = '#';
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= m; ++j)
                putchar(a[i][j]);
            puts("");
        }
        puts("");
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= m; ++j)
                putchar(b[i][j]);
            puts("");
        }
        return 0;
    }
    

    \[\_EOF\_ \]

  • 相关阅读:
    人月神话读后感2
    大三学习进度13
    大三学习进度16
    大三学习进度14
    大三学习进度11
    大三学习进度15
    人月神话读后感3
    大三学习进度10
    Linux设备树
    clk_enable
  • 原文地址:https://www.cnblogs.com/xixike/p/15742535.html
Copyright © 2011-2022 走看看