The 11th Intramural Simulation of the Blue Bridge Cup

1.

[Problem description]
In computer storage, how many MB is 15.125GB?
[Answer submission]
This is a question with the result filled in the blank, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. Fill in the extra content will not be able to score.
Solution: 1GB=1024MB 15.125GB=1024*15.125MB=15488MB
Final result: 15488

[Problem description]
How many divisors does 1200000 have (only positive divisors are calculated).
[Answer submission]
This is a question with the result filled in the blank, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. Fill in the extra content will not be able to score. Solution: Use the Eratosthenes sieve method. Note that the normally opened array int is almost as large as 10^5, so if the title is so large, it should be opened with static in the static area, or use new, delete to apply for a larger space in the heap , code show as below:

Final answer: 92938

#include <iostream>

using namespace std;

const int Maxn=1.3e6;

static int prime[Maxn];
static bool p[Maxn]={
    
    0};
int pNum=0;

void findPrime(int scope){
    
    
    for(int i=2;i<=scope;i++){
    
    
        if(p[i]==false){
    
    
            prime[pNum++]=i;
            for(int j=i+i;j<=scope;j+=i)
                p[j]=true;
        }
    }
}

int main()
{
    
    
    int scope;
    cin>>scope;
    findPrime(scope);
    cout<<scope<<"以内的正约数个数为: "<<pNum<<endl;
}
3.

[Problem description]
A binary tree with 2019 nodes contains at most how many leaf nodes?
[Answer submission]
This is a question with the result filled in the blank, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. Fill in the extra content will not be able to score.

Solution: When the maximum number of leaf nodes is a complete binary tree, the number of full binary tree nodes of 10 layers is 2^10-1, which is 1023. The 2019 nodes given by the title are a total of 11 layers of complete binary trees. There are 996 nodes in the 11th layer, all of which are leaf nodes, but don't forget that the nodes without child nodes in the tenth layer are also leaf nodes. The 996 leaf nodes in the eleventh layer correspond to 498 nodes, and the tenth layer The remaining nodes are also leaf nodes. The 10th layer has a total of 2^9 nodes, which is 512. Then there are 512-498=14 leaf nodes. Finally, the leaves of the tenth and eleventh layers are connected. Add points to get 14+1023=1037
Final answer: 1037

.

[Question description]
From 1 to 2019, how many digits contain the number 9?
Note that some numbers contain more than one 9, and this number is only counted once. For example, the number 1999 contains the number 9, which is just a number in the calculation.
[Answer submission]
This is a question with the result filled in the blank, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. Fill in the extra content will not be able to score.
Solution: The program is as follows
Final answer: 544

//计算1~n中含有数字k的数字的个数
#include <iostream>

using namespace std;

int n,k;
int ans=0;

void judge(int x){
    
    
    while(x){
    
    
        if(x%10==k){
    
    
            ans++;
            break;
        }
        x/=10;
    }
}

int main()
{
    
    
    cout<<"请输入n:";
    cin>>n;
    cout<<"请输入k:";
    cin>>k;
    for(int i=1;i<=n;i++)
        judge(i);
    cout<<"ans="<<ans<<endl;
    return 0;
}

5.

[Problem description]
If any digit of a positive integer is not greater than the adjacent digit on the right, it is called a digit-increasing number. For example, 1135 is a digit-increasing number, while 1024 is not a digit-increasing number.
Given a positive integer n, how many incrementing digits are there in the integers 1 to n?
【Input format】
The first line of input contains an integer n.
[Output format] The
output line contains an integer representing the answer.
[Sample input]
30
[Sample output]
26
[Evaluation case scale and convention]
For 40% of the evaluation use cases, 1 <= n <= 1000.
For 80% of the evaluation cases, 1 <= n <= 100000.
1 <= n <= 1000000 for all evaluation cases.

code show as below

//计算1 至 n 中有多少个数位递增的数
#include <iostream>

using namespace std;

const int  Maxn=1e6+10;

int n;
int ans=0;

bool judge(int x){
    
    
    int right=Maxn;//记录当前数字的个位数
    while(x){
    
    
        if((x%10)>right){
    
    
            return false;
            break;
        }
        right=x%10;
        x/=10;
    }
    return true;
}

int main()
{
    
    
    cin>>n;
    for(int i=1;i<=n;i++)
        if(judge(i)==true)
            ans++;

    cout<<ans<<endl;
    return 0;
}


6. [Problem description]
In the sequence a[1], a[2], …, a[n], if the subscripts i, j, k satisfy 0<i<j<k<n+1 and a[ i]<a[j]<a[k], then a[i], a[j], a[k] are said to be a set of increasing triples, and a[j] is the center of the increasing triples.
Given a sequence, ask how many elements in the sequence may be the center of an increasing triple.
【Input format】
The first line of input contains an integer n.
The second line contains n integers a[1], a[2], …, a[n], and the adjacent integers are separated by spaces, indicating the given sequence.
[Output format] The
output line contains an integer representing the answer.
[Sample input]
5
1 2 5 3 5
[Sample output]
2
[Sample description]
a[2] and a[4] may be the center of the triplet.
[Evaluation case scale and convention]
For 50% of the evaluation cases, 2 <= n <= 100, 0 <= the number in the sequence <= 1000.
For all evaluation cases, 2 <= n <= 1000, 0 <= number in sequence <= 10000.

The analysis
only needs to satisfy that there are elements smaller than him on the left and elements larger than him on the right. Here we create a structure, in addition to saving the value of the node, it also saves the minimum value l_Min on the left and the maximum value r_Max on the right, These two values ​​only need to be traversed twice from the beginning to the end and from the end to the beginning. The code is as follows

//给定一个数列,计算数列中有多少个元素可能是递增三元组的中心
#include <iostream>

using namespace std;

const int Maxn=1e4+10;
const int INF=0x3f3f3f3f;

int n;

struct Node{
    
    
    int l_Min;//该元素左边最小的数
    int r_Max;//该元素右边最大的数
    int value;//该元素的值
};

Node node[Maxn];

int main()
{
    
    
    int l_Min=INF;
    int r_Max=-1;
    int ans=0;
    cin>>n;
    //输入并且找到每个元素左边最小的数
    for(int i=1;i<=n;i++){
    
    
        cin>>node[i].value;
        node[i].l_Min=l_Min;
        if(node[i].value<l_Min)
            l_Min=node[i].value;
    }

    //找每个元素右边最大的数并计算满足三元组中心条件的个数
    for(int i=n;i>=0;i--){
    
    
        node[i].r_Max=r_Max;
        if(node[i].value>r_Max)
            r_Max=node[i].value;
        if(node[i].value>node[i].l_Min&&node[i].value<node[i].r_Max)
            ans++;
    }

    cout<<ans<<endl;
    return 0;
}



7. [Problem description]
Xiao Ming is very interested in words like hello. This kind of word can be divided into four paragraphs. The first paragraph consists of one or more consonants, and the second paragraph consists of one or more vowels. It consists of letters, the third segment consists of one or more consonants, and the fourth segment consists of one or more vowels.
Given a word, please determine whether the word is also such a word, if so, please output yes, otherwise please output no.
There are five vowels including a, e, i, o, u, and the others are consonants.
[Input format]
Enter a line, including one word, and the word only contains lowercase English letters.
[Output format]
Output the answer, either yes or no.
[Sample input]
lanqiao
[Sample output]
yes
[Sample input]
world
[Sample output]
no
[Evaluation case scale and convention]
For all evaluation cases, the number of letters in a word should not exceed 100.

code show as below

#include <iostream>
#include <string>
using namespace std;

char five[5]={
    
    'a','e','i','o','u'};

bool inFive(char c){
    
    
    for(int i=0;i<5;i++)
        if(c==five[i])
            return true;
    return false;
}

int main()
{
    
    
    string str;
    cin>>str;
    int pos=0;
    int stage=1;

    while(pos<str.size()){
    
    
        if(stage==1){
    
    
            if(inFive(str[pos])){
    
    
                cout<<"no"<<endl;
                break;
            }
            while(!inFive(str[pos])&&pos<str.size())
                pos++;
            if(inFive(str[pos])&&pos<str.size())
                stage++;
        }
        else if(stage==2){
    
    
            while(inFive(str[pos])&&pos<str.size())
                pos++;
            if(!inFive(str[pos])&&pos<str.size())
                stage++;
        }
        else if(stage==3){
    
    
            while(!inFive(str[pos])&&pos<str.size())
                pos++;
            if(inFive(str[pos])&&pos<str.size())
                stage++;
        }
        else if(stage==4){
    
    
            while(inFive(str[pos])&&pos<str.size())
                pos++;
            if(!inFive(str[pos])&&pos<str.size())
                stage++;
        }
    }
    if(stage==4)
        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;
    return 0;
}



8.

[Problem description]
Xiao Ming has an open space. He divides the open space into small blocks with n rows and m columns, and the length of each row and column is 1.
Xiaoming chose some of the small pieces of open space and planted grass, and the other small pieces remained open space.
These grasses grow very fast. Every month, the grass will grow out a little. If a small piece of grass is planted, it will expand to its own upper, lower, left, and right four small pieces of open space. These four small pieces of open space will become grassy patches.
Please tell Xiao Ming where there will be grass in the open space after k months.
【Input format】
The first line of input contains two integers n, m.
The next n lines, each containing m letters, represent the initial open space state, with no spaces between letters. If it is a decimal point, it means open space, and if the letter is g, it means grass is planted.
Next contains an integer k.
[Output format]
Output n lines, each line contains m letters, indicating the state of the open space after k months. If it is a decimal point, it means an open space, and if the letter is g, it means grass grows.
【Sample input】
4 5
.g…

g…
2
Sample
output
gggg
. = 20. For 70% of the evaluation cases, 2 <= n, m <= 100. For all evaluation cases, 2 <= n, m <= 1000, 1 <= k <= 1000.








9.

[Problem description]
Xiaoming wants to know the number of positive integer sequences that satisfy the following conditions:
1. The first item is n;
2. The second item does not exceed n;
3. Starting from the third item, each item is less than the previous two items The absolute value of the difference.
Calculate, for a given n, how many sequences satisfy the condition.
【Input format】The
input line contains an integer n.
【Output format】
Output an integer to represent the answer. The answer may be large, please output the remainder of dividing the answer by 10000.
[Sample input]
4
[Sample output]
7
[Sample description]
The following is the sequence that satisfies the conditions:
4 1
4 1 1
4 1 2
4 2
4 2 1
4 3
4 4
[Evaluation case scale and convention]
For 20 1 <= n <= 5
for % of test cases; 1 <= n <= 10 for 50% of test cases;
1 <= n <= 100 for 80% of test cases; 1 <= n <= 100
for all test cases = n <= 1000.



10. [Problem description] Xiao Ming wants to organize a party, and has prepared n programs in total. Then the time for the party is limited, and he can only choose m programs in the end.
These n programs are given in the order Xiao Ming imagined, and the order cannot be changed.
Xiao Ming found that the audience's liking for the evening has a great relationship with the goodness of the previous programs. He hopes that the first program selected is as good as possible. On this premise, he hopes that the second program is as good as possible. analogy.
Xiao Ming defines a good-looking value for each program. Please help Xiao Ming choose m programs to meet his requirements.
【Input format】
The first line of input contains two integers n, m, which represent the number of programs and the number to be selected.
The second line contains n integers, followed by the good looks for each show.
[Output format]
The output line contains m integers, which are the good-looking values ​​of the selected program.
[Sample input]
5 3
3 1 2 5 4
[Sample output]
3 5 4
[Sample description]
The 1st, 4th, and 5th programs are selected.
[Evaluation case scale and convention]
For 30% of evaluation cases, 1 <= n <= 20;
for 60% of evaluation cases, 1 <= n <= 100;
for all evaluation cases, 1 <= n <= 100000, 0 <= the show's good looks value <= 100000.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325390766&siteId=291194637