码迷,mamicode.com
首页 > 其他好文 > 详细

Sicily 14551. Jury Jeopardy

时间:2015-06-02 08:06:10      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

Sicily 14551. Jury Jeopardy

题目

技术分享

思路

给定DFS路径,还原地图。

代码

#include <stdio.h>
#include <string.h>

const short DIR[4][2] = { 0, 1, 1, 0, 0, -1, -1, 0 };

int main() {
    int caseNum;
    scanf("%d", &caseNum);
    printf("%d\n", caseNum);
    while (caseNum--) {
        char map[105][105], Move[20000];
        scanf("%s", Move);
        short minI = 105, minJ = 0, maxI = -1, maxJ = -1, pi = 0, pj = 0, dir = 0, P[20000][2], p = 1;
        P[0][0] = 0, P[0][1] = 0;
        for (int i = 0; Move[i] != ‘\0‘; i++) {
            if (Move[i] == ‘R‘) dir = (dir + 1) & 3;
            else if (Move[i] == ‘L‘) dir = (dir + 3) & 3;
            else if (Move[i] == ‘B‘) dir = (dir + 2) & 3;
            pi += DIR[dir][0];
            pj += DIR[dir][1];
            P[p][0] = pi;
            P[p][1] = pj;
            p++;
            if (pi < minI) minI = pi;
            if (pi > maxI) maxI = pi;
            if (pj > maxJ) maxJ = pj;
        }
        int width = maxJ - minJ + 1 + 1;
        int height = maxI - minI + 1 + 2;
        printf("%d %d\n", height, width);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) map[i][j] = ‘#‘;
            map[i][width] = ‘\0‘;
        }
        if (minI < 0) minI = -minI;
        if (minJ < 0) minJ = -minJ;
        for (int i = 0; i < p; i++) map[P[i][0] + minI + 1][P[i][1] + minJ] = ‘.‘;
        for (int i = 0; i < height; i++) printf("%s\n", map[i]);
    }

    return 0;
}

Sicily 14551. Jury Jeopardy

标签:

原文地址:http://blog.csdn.net/u012925008/article/details/46322939

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!