• Uva 11520


    题目

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515


    题意

    n*n矩阵中填入大写字母,n <= 10,要求从上到下从左到右字母序最小,相邻格子字母不同

    思路

    如刘书思路,状态比较小,不会导致矛盾。

    感想

    1. 状态较小

    代码

    #include <algorithm>
    #include <cassert>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <tuple>
    #define LOCAL_DEBUG
    using namespace std;
    typedef pair<double, int> MyPair;
    const int MAXN = 11;
    int dx[4] = { 1, -1, 0, 0 };
    int dy[4] = { 0, 0, 1, -1 };
    char maze[MAXN][MAXN];
    bool used[26];
    void fillin(int i, int j, int n) {
        memset(used, 0, sizeof used);
        for (int di = 0; di < 4; di++) {
            int tx = i + dx[di];
            int ty = j + dy[di];
            if (0 > tx || tx >= n)continue;
            if (0 > ty || ty >= n)continue;
            if (maze[tx][ty] == '.')continue;
            used[maze[tx][ty] - 'A'] = true;
        }
    }
    
    
    int main() {
    #ifdef LOCAL_DEBUG
        freopen("C:\Users\Iris\source\repos\ACM\ACM\input.txt", "r", stdin);
        //freopen("C:\Users\Iris\source\repos\ACM\ACM\output.txt", "w", stdout);
    #endif // LOCAL_DEBUG
        int T;
        scanf("%d", &T);
        for (int ti = 1; ti <= T; ti++) {
            int n;
            scanf("%d", &n);
            for (int i = 0; i < n; i++)scanf("%s", maze + i);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (maze[i][j] != '.')continue;
                    fillin(i, j, n);
                    for (char c = 'A'; c <= 'Z'; c++) {
                        if (!used[c - 'A']) {
                            maze[i][j] = c;
                            break;
                        }
                    }
                }
            }
            printf("Case %d:
    ", ti);
            for (int i = 0; i < n; i++)printf("%s
    ", maze[i]);
            
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    Python生成验证码
    Django设置
    OpenStack安装后检查流程总结
    利用src.rpm包修改源码后重新制作rpm包
    Python知识点:distutils常用子模块
    libvirt, libvirt-python, libvirtd 关系浅析
    Python知识点: os.popen
    Python知识点: __import__
    修改initrd.img里ko文件的一个小tips
    关于openstack自动化安装的一点思考
  • 原文地址:https://www.cnblogs.com/xuesu/p/10389111.html
Copyright © 2020-2023  润新知