zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    PHP中的list方法
    PHP通过引用传递参数
    PHP浮点数的精确计算BCMath
    cssViewer牛逼的chrome插件
    Chrome浏览器插件VisualEvent,可以方便的查看页面绑定的事件
    Javascript水平提升
    360良心制作fonts.useso.com
    PHP函数htmlspecialchars_decode
    ecshop移动端支付宝支付对接
    转:阿里旺旺导致python安装包失败的解决办法
  • 原文地址:https://www.cnblogs.com/xuesu/p/10389111.html
Copyright © 2011-2022 走看看