博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2019 CCPC网络选拔赛题
阅读量:3957 次
发布时间:2019-05-24

本文共 3229 字,大约阅读时间需要 10 分钟。

第一次写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 31 2 3 4 5343

Sample Output

3 4 1 2 5

解题思路:

这个题正常去写的话会时间超限,就是每一次输入m中的数,前面的数就要整体后移,这样就会时间超限,所以这个题就是把n、m的数分别存入a[]、b[]两个数组中,然后再定义一个book[]数组,每一次输出之后就把数标记一下。

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

程序代码:

#include
#include
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

3123

Sample Output

CCPCCCCCPCPCPPCCCPPCCCCCCCCCPCPCPCPCPPCCPPCCCPPCCPPCPPPPCCCCCPCPPCPCCCPPPPCCPCCPCPPC

解题思路:

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

程序代码:

#include
#include
#include
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;}

转载地址:http://uexzi.baihongyu.com/

你可能感兴趣的文章
10款免费且开源的项目管理工具
查看>>
java调用javascript :js引擎rhino
查看>>
asp 中常用的文件处理函数
查看>>
ADO中sqlserver存储过程使用
查看>>
Linux KernelTech版FAQ 1.0
查看>>
ntfs分区iis故障的解决
查看>>
个人创业“六大死穴”
查看>>
最重要的 12个 J2EE 最佳实践
查看>>
通过Java Swing看透MVC设计模式
查看>>
Java 理论与实践: 关于异常的争论
查看>>
编写高效的线程安全类
查看>>
提高Java代码可重用性的三个措施
查看>>
编写跨平台Java程序注意事项
查看>>
富人和穷人的12个经典差异
查看>>
java 注意事项[教学]
查看>>
MetaWeblogAPI测试
查看>>
软件配置管理概念-1,介绍
查看>>
软件配置管理概念-2,用户角色
查看>>
软件配置管理概念-3,CM系统的概念
查看>>
JSP/Servlet应用程序优化八法
查看>>