1023 The Fun Number System
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 6859
Accepted: 2132
Description
In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤ i < k-1) is 2^i. For example, a 3 bit number 101 is -2^2 + 0 + 2^0 = -3. A negatively weighted bit is called a negabit (such as the most significant bit in a 2's complement number), and a positively weighted bit is called a posibit.
A Fun number system is a positional binary number system, where each bit can be either a negabit, or a posibit. For example consider a 3-bit fun number system Fun3, where bits in positions 0, and 2 are posibits, and the bit in position 1 is a negabit. (110)Fun3 is evaluated as 2^2-2^1 + 0 = 3. Now you are going to have fun with the Fun number systems! You are given the description of a k-bit Fun number system Funk, and an integer N (possibly negative. You should determine the k bits of a representation of N in Funk, or report that it is not possible to represent the given N in the given Funk. For example, a representation of -1 in the Fun3 number system (defined above), is 011 (evaluated as 0 - 2^1 + 2^0), and
representing 6 in Fun3 is impossible.
Input
The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case is given in three consecutive lines. In the first line there is a positive integer k (1 ≤ k ≤ 64). In the second line of a test data there is a string of length k, composed only of letters n, and p, describing the Fun number system for that test data, where each n (p) indicates that the bit in that position is a negabit (posibit).
The third line of each test data contains an integer N (-2^63 ≤ N < 2^63), the number to be represented in the Funk number
system by your program.
Output
For each test data, you should print one line containing either a k-bit string representing the given number N in the Funk number system, or the word Impossible, when it is impossible to represent the given number.
Sample Input
2
3
pnp
6
4
ppnn
10
Sample Output
Impossible
1110
Source
Tehran 2002, First Iran Nationwide Internet Programming Contest
/*엉망진창, 처음에는 생각이 없어서...자신의 제목을 경멸하는 것은 1열 2진법을 정하는 것이다. 이 2진법의 유일한 차이점은 가능감하고 이어서 N을 정하는 것이다. 이 2진법으로 간단한 사고방식을 나타낼 수 있느냐고 묻는다. 낮은 위치에서 높은 위치로 먼저 n이 홀수인지 아닌지를 판단하고if(n&1)/n이 마이너스인지 아닌지로 판단해도 된다.고위로 한 분 가다가 마지막 한 분이 옳다면 (n-1)>>1로 바뀌고, 고위로 한 분 모든 자리를 다 걷고 나면 n이 0이 되지 않으면 풀리지 않습니다.반면 주의 n은 음수*/#include
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Access Request, Session and Application in Struts2If we want to use request, Session and application in JSP, what should we do? We can obtain Map type objects such as Req...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.