2019年北京西城区青少年人工智能创意编程活动初中组试题参考答案

一、客观题

1 B

2 A

3 D

4 A

5 C

二、完成程序

评测结果:

2019年北京西城区青少年人工智能创意编程活动初中组试题参考答案_第1张图片
result.png

T1

AC代码:

#include
#include

int main()
{
    freopen("T1.in", "r", stdin);
    freopen("T1.out", "w", stdout);
    
    int n;
    scanf("%d", &n);
    printf("%d=", n);
    for(int i=2; i<=sqrt(n); i++)
    {
        if(0 == n%i)
        {
            n /= i;
            printf("%d*", i--);
        }
    }
    printf("%d\n", n);  // 输出最后一个数

    return 0;
}

T2

AC代码:

#include 
#include 
#include 
using namespace std;

int main()
{
    freopen("T2.in", "r", stdin);
    freopen("T2.out", "w", stdout);

    int k, n;
    cin >> k >> n;

    int bit = 0;    // 第几位,从最低位算起
    long long res = 0;
    while(n)
    {
        if(n % 2)
        {
            res += (long long)pow(k, bit);
        }

        bit++;
        n /= 2;
    }

    cout << res;

    return 0;
}

T3

AC代码:

#include 
#include 
using namespace std;

const int maxSize = 200000;     // 总共有多少个坐标点
const int maxJumpPos = 2 * maxSize + 5; // 最多可以跳两倍,再稍微大一点 

struct node
{
    int x;
    int step;
    node(int xx,int s):x(xx),step(s) {}
};

int visited[maxJumpPos];
int N,K;
queue q;

void BFS(int x,int step)
{
    q.push(node(x,step));
    visited[x] = 1;

    while(!q.empty())
    {
        node head = q.front();
        if(head.x == K)
        {
            printf("%d\n",head.step);
            return ;
        }
        else
        {
            if(!visited[head.x + 1] && head.x + 1 <= maxSize)
            {
                visited[head.x + 1] = 1;
                q.push(node(head.x + 1,head.step+1));
            }

            if(!visited[head.x-1] && head.x-1 >= 0)
            {
                visited[head.x - 1] = 1;
                q.push(node(head.x - 1,head.step+1));
            }

            if(!visited[2 * head.x] && 2 * head.x <= maxSize)
            {
                visited[2 * head.x] = 1;
                q.push(node(2 * head.x,head.step + 1));
            }

            q.pop();
        }
    }
}


int main()
{
    freopen("T3.in", "r", stdin);
    freopen("T3.out", "w", stdout);

    scanf("%d%d",&N,&K);

    BFS(N,0);

    return 0;
}

了解少儿编程、信息学竞赛请加微信307591841或QQ307591841


2019年北京西城区青少年人工智能创意编程活动初中组试题参考答案_第2张图片
信息学竞赛公众号.jpg

你可能感兴趣的:(2019年北京西城区青少年人工智能创意编程活动初中组试题参考答案)