2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(解题报告)

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<math.h>
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<stdio.h> 
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;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值