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

建议使用的浏览器:

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

2213:Code

题目描述
The important thing is also the fact, where the representatives sit in the Parliament. Some of them prefer front rows because of more light, some prefer back rows because of less light and more silence. The others want to sit by the window. Moreover, the sitting order must be kept absolutely secret, because the neighbouring representatives may influence each other. Since we do not want to have corruption in the Parliament, it was decided to use Hyper-secret Code to encrypt the numbers of seats. The Hyper-secret Code of length n is designated SK(n) and consists of all possible binary strings of length n. That means it always has 2n elements. The Code is generated using the following recursive algorithm:
  • SK(1) = [0, 1]
    SK(n) = 0.SK(n-1) + 1.REV{SK(n-1)}

in which
  • [0, 1] is succession of two binary strings of length one. The first of them is "0" and the second is "1".
  • b.SK(x) is the code created from SK(x) such that the binary digit b is prepended to the beginning of each string in succession SK(x).
  • REV{SK(x)} is the reverse succession to SK(x), it means the first string becomes the last one.
    Note that the ordering of whole strings is reversed, not the ordering of digits inside the string.
  • X + Y is the concatenation of successions X and Y.

Every seat in the Parliament has its own number. The numbers make a continuos succession beginning with one. The Hyper-secret Code SK(n) is generated (using the above algorithm) for greater and greater n, until the length of the Code (the number of binary strings that form the succession) is greater or equal to the highest number of seat. Every seat s is then given the binary string that appears at the s-th possition in the succession SK(n). Every representative then gets the Code of his seat and nobody can determine who is going to be his neighbour.

But the problem appears when the representative enters the Parliament, takes the paper with his Code and finds his seat. To solve this, the Chairman of the Parliament wants the computer program that will be able to convert any Hyper-secret Code to the appropriate number of a seat. You propably guess that you are to write this program.
输入解释
At the first line there is a positive integer N stating the number of assignments to follow. Each assignment consists of two lines. The first line contains an integer number k, 1 <= k <= 30. At the second line, there is the Hyper-secret Code consisting of exactly k characters. Each of the characters is either 0 or 1.
输出解释
The program should print the line for each assignment. The line must contain the sentence "Poslanec P se posadi na sedadlo cislo S." (The representative #P sits down at the seat S). Fill the number of the assignment (starting with one) instead of P, and the right number of a seat instead of S - it means the possition of the given string in the Code SK(k).
输入样例
5
1
0
4
0000
4
1000
4
1111
8
10101010
输出样例
Poslanec 1 se posadi na sedadlo cislo 1.
Poslanec 2 se posadi na sedadlo cislo 1.
Poslanec 3 se posadi na sedadlo cislo 16.
Poslanec 4 se posadi na sedadlo cislo 11.
Poslanec 5 se posadi na sedadlo cislo 205.

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

题目来源 CTU FEE Local 1998

源链接: POJ-2213

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

共提交 0

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