UVa10851 - 2D Hieroglyphs decoder(枚举)

来源:互联网 发布:微博淘宝优惠券 编辑:程序博客网 时间:2024/05/29 17:45

The Problem

Steganography is one of the most famous techniques for hiding information in different places, including images. Recently, for example, Xerox announced they were releasing a 2D-hieroglyphs that were able to codify a message within them. Your task is to decipher a 2D-hieroglyph.

A 2D hieroglyph is a matrix $ H$ of 10 rows and $ M+2$ columns that encode a message of length $ M$characters ( $ c_0, c_1, \ldots, c_{M-1}$). The matrix $ H$ has the following lattice:

$\displaystyle H_{i,j} =\left\lbrace \begin{array}{ll}'/' & \forall i=0, j \in...... 2, \ldots , 8\right), j \in \left(1, 2, \ldots , M\right)\end{array} \right.$

where

$\displaystyle b(i,c) =\left\lbrace \begin{array}{ll}'/' & \mathrm{if}\ \left(......m{if}\ \left( \frac{c}{2^i} \right) \mathrm{mod}\ 2 = 1\\\end{array} \right.$

and $ c$ is the ASCII value of the character passed to the $ b$ function.

Your task is to find the message given the matrix $ H$.

The Input

The input is composed of a first line with a number $ N$ indicating the number of messages to decode, followed by $ N$ matrices separated by a "newline" character. The length of any message will not be more than 80 characters.

The Output

The output must have $ N$ messages, one per each matrix given in the input.

Sample Input

2/////////////////////////////////////////\///\/\\/\//\\/\//\/\\/\/\/\\/\/\//\////////\////\/\/\//////\//\////\/\//////\//\\\\///\\//\\/\\//\//\\//\///\/\\///\//\\//\///\////\\\//////\//\////\\\////////\\//////\/\//////\/\/////\/\////////\//////\//\///////\//\///\///////////\\/\\\\\\/\\/\\\\\\\/\\/\\\/\\\\\\\\\///////////////////////////////////////////////////////////////////////////////////////////\/\/\/\/\///\\//\\///////\\\\///////////\\/////////////\\\\\\\\\//\\\\\\\\\///////////////////////

Sample Output

LA LLUVIA EN SEVILLA ES UNA MARAVILLAabcdefghi
import java.io.FileInputStream;import java.io.BufferedReader;import java.io.BufferedInputStream;import java.io.InputStreamReader;import java.io.StreamTokenizer;import java.io.PrintWriter;import java.io.OutputStreamWriter;import java.util.Scanner;public class Main implements Runnable{private static final boolean DEBUG = false;private static final int ROW = 10;private static final int[] exp = {1, 2, 4, 8, 16, 32, 64, 128};private Scanner cin;private PrintWriter cout;private String[] s;private void init() {try {if (DEBUG) {cin = new Scanner(new BufferedInputStream(new FileInputStream("e:\\uva_in.txt")));} else {cin = new Scanner(new BufferedInputStream(System.in));}cout = new PrintWriter(new OutputStreamWriter(System.out));} catch (Exception e) {e.printStackTrace();}}private void input() {s = new String[ROW];for (int i = 0; i < ROW; i++) {s[i] = cin.next();}}private char check(int col){for (int i = 0; i < 255; i++) {boolean ok = true;for (int j = 0; j < ROW - 2 && ok; j++) {if (i / exp[j] % 2 == 1 && s[j + 1].charAt(col) == '/') ok = false;else if (i /exp[j] % 2 == 0 && s[j + 1].charAt(col) == '\\') ok = false;}if (ok) return (char)i;}return (char)-1;}private void solve() {int M = s[0].length() - 2;StringBuilder sb = new StringBuilder();for (int i = 1; i <= M; i++) {char ch = check(i);if (ch != -1) sb.append(ch);}cout.println(sb.toString());cout.flush();}public void run(){init();int t = cin.nextInt();while (t-- > 0) {input();solve();}}public static void main(String[] args) {new Thread(new Main()).start();}}



0 0