Blue Bridge Cup Questions (Examination Questions for the First Blue Bridge Cup International Competition)

A. Warehouse layout:
data range:
only need to care about the maximum value: n is up to 10 9 , m is up to 10 9,
there is no need to consider the data range. As long as the int is okk
code:

#include<bits/stdc++.h>
using namespace std;
int n,m;
int val(){
    
    
    int k=m-1;
    int tag=1;
    if(n%3==0) tag=0;
    return n/3*k*2+tag*(n%3-1)*k;
}
int main(){
    
    
    cin>>n>>m;
    cout<<val();
}

Anyway, after the sample, it's probably fine. This question is to push the formula, as long as it is a multiple of three, then it can be divided into three rows of small units of one unit. If modulo 3 is equal to 1, what is the situation if modulo 3 is equal to 2 is very clear.

B website expansion:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int add[310]={
    
    0};
    int input;
    cin>>input;
    int sum=0;
    add[1]=1;
    for(int i=1; i<=input; i++) //代表起点
    {
    
    
        sum+=add[i];
        if(add[i])
            for(int j=i+7; j<=input; j+=3)
            {
    
    
                add[j]+=add[i];
            }
    }
    cout<<sum;
    return 0;
}

Just simulate violence and the solution is OK. After all, the data is too small to find a pattern.

C base pairing:
KMP at a glance, okay (
slowly change, a little dizzy, climb first

Guess you like

Origin blog.csdn.net/weixin_47741017/article/details/114383217