第31届ICPC北京赛区网络试题(C,D)
<P>Encryption(C) <BR>Time Limit:5S Memory Limit:32768K<BR>Description<BR>Country C recently intercepts a telegram from enemy army, but the telegram is encrypted. Analysis indicates that it is encrypted in WLE method. The decoding team spends a week to make a decoding solution:<BR>The encrypted message is a non-decreasing nonnegative integer sequence with the length of m. The decoding solution consists of several steps, each of which is one of the following cases:<BR>1. Subtract a positive integer from every number in the sequence, then delete negative terms.<BR>2. Delete the first t terms of the sequence (t is a positive integer). If t is bigger than the length of the sequence, the sequence is empty.<BR>3. Generate a new sequence with the same length as the original one. The nth term in the new sequence is the number of terms that are smaller than n in the original sequence. (n=1,2,...)<BR>As a senior software engineer of Country C, you need to make a decoder.<BR>Input<BR>Input consists of multiple test cases. <BR>Each case begins with a line containing n (100<=n<=10000), the length of the encrypted sequence, followed by n nonnegative integers in non-decreasing order. The next line contains m (100<=m<=10000), the number of decoding steps. The following m lines specify the operation of each step in such format as (corresponding to the problem description):<BR>The first case: a single character 'M' followed by a positive integer.<BR>The second case: a single character 'D' followed by a positive integer.<BR>The third case: a single character 'N'.<BR>There is no blank between the character and the integer. Every positive integer except m and n is less than or equal to 50.<BR>The last case is followed by a line containing a zero.<BR>Output<BR>For each case, output the decoded sequence. If the decoded sequence is empty, output 'Empty'.<BR>Sample Input<BR>5<BR>1 2 3 4 5<BR>3<BR>M1<BR>D1<BR>N<BR>5<BR>1 2 3 4 5<BR>3<BR>M1<BR>D1<BR>N<BR>5<BR>1 2 3 4 5<BR>1<BR>D10<BR>0<BR>Sample Output<BR>Case 1: 0 1 2 3<BR>Case 2: 0 1 2 3<BR>Case 3: Empty</P><P>Genius(D) <BR>Time Limit:1.5S Memory Limit:65536K<BR>Description<BR>For each natural number N (N>0),<BR>Primary school students know if there exists an integer a, such that a2=N, then N is a perfect square.<BR>Junior school students know if sqrt(N) is an irrational number, N is not a perfect square(square-free). High school students know that N is a perfect square if and only if there exists two positive integers X and Y, such that N=X2/Y2.<BR>College students know that N is square-free if and only if there exists two positive integers X and Y, such that N=(X2-1)/Y2. <BR>As a mathematics and programming genius, you know far more than them. Not only are the above four simple propositions a piece of cake to you, but also you can tell them how much X and Y are for each square-free N, such that (X2-1)/Y2=N.<BR>You need to write a program which inputs an integer N and outputs X and Y.<BR>Such X and Y may be multiple. Please output the minimum X and Y.<BR>Input<BR>The input consists of several test cases. Each test case is in a separate line, and consists of a single integer in the range 1 ... 10^8.<BR>The last case is followed by a line containing an integer zero.<BR>Output<BR>For each test case, display a line that contains X and Y. if either X or Y is greater than or equal to 10^1000, output 'No solution!'.<BR>Sample Input<BR>3<BR>57<BR>81<BR>0<BR>Sample Output<BR>Case 1:<BR>2 1<BR>Case 2:<BR>151 20<BR>Case 3:<BR>No solution!<BR></P>
页:
[1]

