Windows Of
In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:
And the 2-nd order CCPC window is shown in the figure:
We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.
Input
The input file contains T test samples.(1<=T<=10)
The first line of input file is an integer T.
Then the T lines contains a positive integers k , (1≤k≤10)
Output
For each test case,you should output the answer .
Sample Input
3
1
2
3
Sample Output
CC
PC
CCCC
PCPC
PPCC
CPPC
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC
解题思路:这道题每个样例的前两行都是可以确定的,以下的每两行都可以从上面一行得到。
#include
char s[2000][2000];
int main()
{
int i,j,l,n,t,k,r;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
r=pow(2,n);
for(i=1;i<=r;i++)
s[1][i]='C';
for(i=1;i<=r;i++)
{
if(i%2!=0)
s[2][i]='P';
else
s[2][i]='C';
}
k=1;
l=3;
for(i=2;i<=r;i++)
{
for(j=1;j<=r;j++)
{
if(s[i][j]=='P')
{
s[l][k]='P';
s[l][k+1]='P';
s[l+1][k]='C';
s[l+1][k+1]='P';
k+=2;
}
else
{
s[l][k]='C';
s[l][k+1]='C';
s[l+1][k]='P';
s[l+1][k+1]='C';
k+=2;
}
}
l+=2;
k=1;//这里每次都需要从第一列开始
}
for(i=1;i<=r;i++)
{
for(j=1;j<=r;j++)
printf("%c",s[i][j]);
printf("\n");
}
}
return 0;
}
Shuffle Card
Problem Description
A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.
Please output the order of cards after m operations.
Input
The first line of input contains two positive integers n and m.(1<=n,m<=105)
The second line of the input file has n Numbers, a sequence of 1 through n.
Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.
Output
Please output the order of cards after m operations. (There should be one space after each number.)
Sample Input
5 3
1 2 3 4 5
3
4
3
Sample Output
3 4 1 2 5
这题就是反向输出m,正向输出n就可以了,输出一个数就得对这个数进行标记,以防重复输出
#include
int book[100100],a[100100],b[100100];
int main(){
int m,n,i,j;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=m;i>0;i--)
scanf("%d",&b[i]);
printf("%d",b[1]);
book[ b[1] ] = 1;
for(i=2;i<=m;i++)
if(book[ b[i] ] == 0){
printf(" %d",b[i]);
book[ b[i] ] = 1;
}
for(i=1;i<=n;i++)
if(book[ a[i] ] == 0){
printf(" %d",a[i]);
book[ a[i] ] =1;
}
printf(" ");
return 0;
}