当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2266:Quadtree

题目描述
While searching for treasures in an ancient Aztec ruin, Florida Jones (the brother of famous Indiana Jones) stumbles across a papyrus roll lettered with a long string of symbols. There are three different symbols occuring in the string which we will call B, W and Q here.
Being somewhat experienced in cryptography, Florida Jones recognizes the code immediately as the famous Quadtree Encoding Scheme that has been invented 3000 years ago.

With the Quadtree system, secret pictures (like treasure maps) were encoded in the following way: If the whole picture was black, it was encoded by the letter B. If it was completely white, it was encoded by W. If both colors were used (what was usually the case), it was encoded by Qxxxx where each x was a string that recursively encoded one quarter of the picture (in the order top left, top right, bottom left, bottom right). As the Aztecs always used quadratic pictures with n*n pixels where n was a power of two, this method always worked perfectly.
A 2*2 chess board, for instance, would be encoded as QWBBW, a 4*4 chess board as QQWBBWQWBBWQWBBWQWBBW.

Your job is to decode the quadtree string and output the picture in the XBM format (see output specification).
输入解释
The input contains an integer n (8 <= n <= 512) on the first line, giving the size of the picture in pixels per row/column. n will always be a power of two.
On the second line, a string consisting of the letters B, W and Q follows. The string encodes a picture with n*n pixels with the quadtree scheme.
输出解释
On the first line, print "#define quadtree_width n" where n is the picture size given in the input.
On the second line, print "#define quadtree_height n" accordingly.
On the third line, print "static char quadtree_bits[] = {".
Then, print n lines (each one encoding one pixel row of the picture) with n/8 hexadecimal numbers per line.
Each hexadecimal number is composed of 8 bits that encode 8 pixels from left to right (where the leftmost bit has the value 1 and the rightmost bit has the value 128). The hexadecimal numbers should be printed in the form 0xdd where d is one character of the set { 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f }.
Example: The 8 pixels WBBBBWWB would be written as 0x9e. (2+4+8+16+128 = 158 = 0x9e)
Print a comma after each hexadecimal number.
On the last line, print "};".
Note: The comments (enclosed by /* and */) in the sample output are not part of the output. They should help to explain the XBM format.
输入样例
16
QQWBBWQWBBWQWBBWQWBBW
输出样例
#define quadtree_width 16
#define quadtree_height 16
static char quadtree_bits[] = {
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0xf0,0xf0,                       /* WWWWBBBB WWWWBBBB */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
0x0f,0x0f,                       /* BBBBWWWW BBBBWWWW */
};
提示
The unix tool xv can display graphics in the XBM format.
So, after you have finished your program, run it with "quadtree | xv -" and have a look at the picture. This may help in debugging.

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Ulm Local 1999

源链接: POJ-2266

最后修改于 2020-10-29T06:28:01+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536