2019 CCPC网络选拔赛题

第一次写CCPC的题感觉很难,还是自己太菜了呀!!!

1006题目:Shuffle Card

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、m的数分别存入a[]、b[]两个数组中,然后再定义一个book[]数组,每一次输出之后就把数标记一下。

注意:这个题没有换行,不是多实例,而且每个数字后面都有一个空格

程序代码:

#include<stdio.h>
#include<string.h>
int a[100010],b[100100],book[200000];
int main()
{
	int i,j,n,m,k;
	memset(book,0,sizeof(book));//数组初始话为0
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);//把n个数存入数组中
	for(i=m;i>=1;i--)
		scanf("%d",&b[i]);//把m个数存入数组中
	for(i=1;i<=m;i++)
	{
		if(book[b[i]]==0)//把b[]数组中的数输出并标记
		{
			printf("%d ",b[i]);
			book[b[i]]=1;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(book[a[i]]==0)
		{
			printf("%d ",a[i]);//把a[]数组中的数输出并标记
			book[a[i]]=1;
		}
	}
	return 0;
}

1007题目:Windows Of CCPC

Problem Description
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

解题思路:
这个题有点找规律的迹象,就是先把前两排输入,然后从第三排开始,看第二排是P还是C,如果是C,就记录为CCPC,如果是P,就记录PPCP。

程序代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
char e[2000][2000];
int main()
{
	int i,j,k,n,m,t;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		m=pow(2,n);
		for(i=1;i<=m;i++)
			e[1][i]='C';
		for(i=1;i<=m;i++)
		{
			if(i%2==0)
				e[2][i]='C';
			else
				e[2][i]='P';
		}
		t=2;
		for(i=3;i<=m;i=i+2)
		{
			k=1;
			for(j=1;j<=m;j=j+2)
			{
				if(e[t][k]=='C')
				{
					e[i][j]='C';
					e[i][j+1]='C';
					e[i+1][j]='P';
					e[i+1][j+1]='C';
					k++;
				}
				else
				{
					e[i][j]='P';
					e[i][j+1]='P';
					e[i+1][j]='C';
					e[i+1][j+1]='P';
					k++;
				}
			}
			t++;
		}
		for(i=1;i<=m;i++)
		{
			for(j=1;j<=m;j++)
				printf("%c",e[i][j]);
			printf("\n");
		}	
	}
	return 0;
}
发布了67 篇原创文章 · 获赞 39 · 访问量 2731

猜你喜欢

转载自blog.csdn.net/qq_44859533/article/details/100041263