2019 CCPC网络选拔赛题

简介: 2019 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;
}
相关文章
|
前端开发 API
基于Jeecgboot前后端分离的聊天功能集成(一)
基于Jeecgboot前后端分离的聊天功能集成(一)
335 0
|
1天前
|
人工智能 运维 安全
|
3天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
363 123
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
|
6天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
540 107
|
2天前
|
Java 数据库 数据安全/隐私保护
Spring 微服务和多租户:处理多个客户端
本文介绍了如何在 Spring Boot 微服务架构中实现多租户。多租户允许单个应用实例为多个客户提供独立服务,尤其适用于 SaaS 应用。文章探讨了多租户的类型、优势与挑战,并详细说明了如何通过 Spring Boot 的灵活配置实现租户隔离、动态租户管理及数据源路由,同时确保数据安全与系统可扩展性。结合微服务的优势,开发者可以构建高效、可维护的多租户系统。
187 127
|
2天前
|
Web App开发 前端开发 API
在折叠屏应用中,如何处理不同屏幕尺寸和设备类型的样式兼容性?
在折叠屏应用中,如何处理不同屏幕尺寸和设备类型的样式兼容性?
222 124
|
2天前
|
人工智能 数据可视化 测试技术
Coze平台指南(3):核心功能-创建智能体与设计角色
Coze 智能体是由大语言模型驱动,通过提示词设定角色,并借助知识库、插件和工作流扩展能力,以执行特定任务的AI助手。对测试工程师而言,精心设计的智能体可显著提升测试效率与质量,关键是要准确理解测试需求,并将其转化为智能体的角色设定和功能配置。建议进一步学习知识库与工作流,以深化应用。

热门文章

最新文章