ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1008. Image Encoding

Be careful, the last charactor is '.' not ',', this reason lead to 2 WA~
Posted by ZLqiang 8 Jan 2011 10:33
Re: Be careful, the last charactor is '.' not ',', this reason lead to 2 WA~
Posted by lado kakahidze 9 Jan 2011 15:19
#include <cstdio>
#include <cassert>
#include <cctype>
#include <utility>

#define x first
#define y second

const int MAX = 16;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int N;
bool brd[MAX][MAX];
int ref[256];

int main () {
    char line[16];
    gets (line);

    static std::pair <int, int> q[MAX * MAX];
    int p3 = 0;

    int a, b;
    int i, j;
    ref[(int)'R'] = 0;
    ref[(int)'T'] = 1;
    ref[(int)'L'] = 2;
    ref[(int)'B'] = 3;
    if (sscanf (line, "%d %d", &a, &b) == 2) {
        q[p3++] = std::make_pair (a, b);
        brd[a][b] = 1;
        for (i = 0; i < p3; ++i) {
            gets (line);
            for (j = 0; isalpha (line[j]); ++j) {
                assert (line[j] == 'R' || line[j] == 'T' || line[j] == 'L' || line[j] == 'B');
                brd[q[i].x + dx[ref[(int)line[j]]]][q[i].y + dy[ref[(int)line[j]]]] = 1;
                q[p3++] = std::make_pair (q[i].x + dx[ref[(int)line[j]]], q[i].y + dy[ref[(int)line[j]]]);
            }
        }

        assert (line[j] == '.');
        printf ("%d\n", p3);
        for (i = 1; i < MAX; ++i)
            for (j = 1; j < MAX; ++j)
                if (brd[i][j])
                    printf ("%d %d\n", i, j);
    } else {
        N = a;
        for (i = 0; i < N; ++i) {
            scanf ("%d %d\n", &a, &b);
            if (i == 0) q[p3++] = std::make_pair (a, b);
            else brd[a][b] = 1;
        }
        printf ("%d %d\n", q[0].x, q[0].y);
        for (i = 0; i < p3; ++i) {
            for (j = 0; j < 4; ++j) {
                if (brd[q[i].x + dx[j]][q[i].y + dy[j]]) {
                    putchar ("RTLB"[j]);
                    brd[q[i].x + dx[j]][q[i].y + dy[j]] = 0;
                    q[p3++] = std::make_pair (q[i].x + dx[j], q[i].y + dy[j]);
                }
            }
            if (i == N - 1)
                putchar ('.');
            else
                putchar (',');
            puts ("");
        }
    }

    return 0;
}
ZLqiang wrote 8 January 2011 10:33
ZLqiang wrote 8 January 2011 10:33