1 Big Movers
Problem Description
Recently, b factory organized a big move, everyone to follow the instructions to change to the designated seat. The indicated content is that the person sitting on position I is moving to position J. Now there are n people in plant B, one to n positions. After the move is also one by one corresponding, change only the rank. After the first move, the degree of bear due to negligence, but also asked you to follow the original instructions for a move. So, the wit of it thought: again according to the instructions to move home once again can restore the first time the appearance of the move. As a result, plant B has carried out an unprecedented three consecutive moves. While we all know that the "wit" of a bear is often worrying, it is inconceivable that this is a real thing. The result of the third move is exactly the same as the result of the first time. So, how many kinds of instructions are going to make this happen? If at least one of the two instructions has a different target location, the two instructions are considered to be not the same.
Input
The first line is an integer TTT, which represents the T-group data. Each set of data contains an integer N (1≤n≤1000000).
Output
For each set of data, output one line of case #i: Then output the result, modulo 1000000007.
Sample Input
2 1 3
Sample Output
Case #1:1 case#2:4
The result of the third move is exactly the same as the first, suggesting that the moving order must conform to the following rules: I-->t--->i
Since it is difficult to deduce directly f (n) (the number of indicators in n positions), it is natural to consider whether there is a recursive relationship between F (n+1) and F (n), which we draw as follows:
Easy-to-get recursive f[n+1]=f (N) +n*f (N-1)
Meanwhile F (0) =f (1) =1 (due to F (2) =f (1) +f (0) =2)
#include <stdio.h>#definell Long Long#defineMAXN 1000001#defineMoD 1000000007intF[MAXN];intMain () {intT,n,i; scanf ("%d",&T); f[1] = f[0] =1; for(i=2; i<=maxn;i++) {F[i]= f[i-1]%mod + (I-1) * (LL) f[i-2]%MoD; F[i]%=MoD; } //F[i] = F[i-1]%mod + (i-1) * (LL) f[i-2]%mod;//written above, causing f[maxn-1],f[maxn-2] ... may be larger than MoD//F[MAXN]%= mod; for(i=1; i<=t;i++) {scanf ("%d",&N); printf ("Case #%d:\n%d\n", I,f[n]); } return 0;}
2. Column Displacement Method decryption
Problem Description
column Displacement method is a classical cipher algorithm in the modification of the method of encryption, the following will be divided into a fixed number of characters (such as 5 a group, 5 is a key), in the order of a set of rows neatly arranged, the last less than a group of no characters, the completion of reading by the column into ciphertext. For example: Original:123456789 key:4 transformed matrix:12345678 9xxx (the last few x means no character, not a space, not a tab, there is no character, the same as) ciphertext:159263748 Another example: the original: Hello, Welcome to my dream world ! Key : 7 transformed Matrix: Hello,welcometo mydreamWorld! xx cipher: Hw DOEETRRLLOELLC adoomm! , my e-w implementation of an encryption using column-shifting method is a breeze for Bob, but it seems a little difficult for Bob to figure out how to write a corresponding decryption device, can you help him?
Input
The first line is an integer TTT that represents the TTT group data. Each set of data contains 222 rows of the first row, a string s (1≤∣s∣≤1e5)), indicating that the second line of ciphertext after the column displacement method is encrypted, an integer K (1≤k≤∣s∣)), A key input that indicates that the original text is encrypted using the column-shift method to guarantee that the cipher string contains only ASCIIcharacters within the range of [0x20,0x7F]
Output
For each set of data, output one line of case #i: Then output a line containing a string s_decrypt, which indicates the plaintext that is obtained after decryption
Sample Input
4 159263748 4 Hw DOEETRRLLOELLC adoomm! , my e w7 is the bestsokaisan1
Sample Output
Case #1:123456789case#2: Hello, Welcome to my dreamworld! Case # 3 is bestcase #4: Sokaisan
The original text obtains the ciphertext through the transformation matrix, we need to obtain the original text through the ciphertext, must rely on the transformation matrix nature (but cannot convert directly to the matrix and then outputs-timeout)
When the corresponding character is found, the output is implemented, in the first example, the first character is the first character of the ciphertext (in fact, the former L=strlen (s)/k+ (strlen (s)%k!=0) character of the cipher corresponds to the first column of the transformation matrix.
When you output the second character and subsequent characters, you must consider whether the last row corresponds to a column of ' X ' (that is, nonexistent), and if so, the next column in the ciphertext is in the previous column +len (that is, strlen (s)/k) + (mod!=0), otherwise +len
This outputs the previous Len line and then determines if the MoD (that is, strlen (s)%K) is 0, not 0, and the last line has a mod element to output, j* (len+1) 1 is the corresponding column in the ciphertext position
#include <stdio.h>#include<string.h>#defineClen 10001CharS[clen];intMain () {intt,k,i,k,j,len,mod,d; scanf ("%d",&T); for(i=1; i<=t;i++) {GetChar (); Gets (s); scanf ("%d",&j); printf ("Case #%d:\n", i); Len= (int) strlen (s)/K; MoD= (int) strlen (s)%K; //Decode for(k=0; k<len;k++) { for(j=0; j<=mod;j++) printf ("%c", s[k+j* (len+ (mod!=0))]); D= k+mod* (len+ (mod!=0)); for(; j<k;j++) printf ("%c", s[d+ (J-mod) *len]);//Spacing to change } if(MoD)//output The last list { for(j=1; j<=mod;j++) printf ("%c", s[j* (len+1)-1]); } printf ("\ n"); } return 0;}
4. Put the PLATE
Problem Description
The cubs are fond of mischief. Today he presented a ESU game to the visitors. He and his visitors took turns to put plates in a regular polygon. The last dish is the winner, who will win a kiss from the loser. After playing two times, the Cubs found that the visitors were aware of the game's winning strategy. Now the little bear is always the initiator, and he wants to know if he can win. Note that the plate cannot intersect or intersect the polygon and cannot be placed outside the polygon. In other words, the point inside the plate cannot be outside the polygon or inside the plate.
Input
The first line is an integer t, which represents the T group data. Each set of data contains 3 numbers n,a,r (4≤n≤,0<a<,0<r< +) N is even, represents the number of sides of a polygon, a represents the edge length of a positive polygon, and r represents the radius of the plate.
Output
for each set of data, output one line of case #i: and then output the result. If the small bear wins, output "Give me a kiss!" Otherwise output "I want to Kiss you!"
Sample Input
2 4 - 2.5 4 5.5 3
Sample Output
Case #1: Give me a kiss! Case # 2 : I want to kissyou!
Because the number of sides of the polygon N is even, it is natural to use the symmetry, that is, the degree of the first Xiangxian try to put the disk in regular polygon, if not put, it is obvious that the disk can not be placed regular polygon
Degree of loss, otherwise as long as the degree of bear symmetry (to the center) to put, no matter when the sale, the degree of bear all win, in fact, as long as the comparison of disk radius and regular polygon center to the edge of the distance can be
#include <stdio.h>#include<math.h>#definePi 3.14159265intMain () {intT,n,i; DoubleA,r; scanf ("%d",&T); for(i=1; i<=t;i++) {scanf ("%D%LF%LF",&n,&a,&R); printf ("Case #%d:\n", i); if(A/(2*tan (pi/n)) >= R) puts ("Give me a kiss!"); ElsePuts"I want to kiss you!"); } return 0;}
2016 "Baidu Star"-Test race