第十屆藍橋杯C++國賽B組部分題解(假題解)

Herod_發表於2020-11-11

A

Ans:7020

#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    for(int x = 2020 ;  ; x ++){
        for(int y = x+1; ; y++){
            if(y*y-x*x == x*x-2019*2019){
                cout<<2019<<" "<<x<<" "<<y<<endl;
                cout<<x+y<<endl;
                return 0;
            }
            if(y*y-x*x > x*x-2019*2019) break;
        }
    }
    return 0;
}

B

Ans:55965365465060

#include <bits/stdc++.h>
#define int long long
using namespace std;
int prime[2000];
int pcnt = 0;
int dp[3000];
bool check(int x){
    for(int i = 2 ; i < x ; i ++){
        if(x%i == 0)
            return false;
    }
    return true;
}

signed main(){
    for(int i = 2; i < 2019 ; i ++){
        if(check(i)){
            prime[pcnt++] = i;
        }
    }
//    for(int i = 0 ; i < pcnt ; i ++){
//        cout<<prime[i]<<endl;
//    }
    dp[0] = 1;
    for(int i = 0 ; i < pcnt ; i ++){
        for(int j = 2019 ; j >= prime[i] ; j --){
            dp[j] += dp[j-prime[i]];
            //if(dp[j] < 0 ) cout<<dp[j]<<endl;
        }
    }
    cout<<dp[2019]<<endl;
    return 0;
}

C

Ans:----

D

Ans:45360

#include <bits/stdc++.h>
#define int long long
using namespace std;


int check(int x){
    int cnt = 0;
    for(int i = 1 ; i <= sqrt(x) ; i ++){
        cnt += (x%i == 0)*2;
        if(i*i == x) cnt --;
    }
    return cnt;
}

signed main(){
    int two = 2*2*2*2;
    int tre = 3*3*3*3;
    int fiv = 5;
    int sev = 7;
    int res = two*tre*fiv*sev;
    for(int i = 1 ; i <= res ; i ++){
        //cout<<i<<" "<<check(i)<<endl;
        if(check(i) == 100){
            cout<<i<<endl;
        }
    }
    cout<<check(res)<<endl;
    return 0;
}

E

Ans:206

#include <bits/stdc++.h>
#define int long long
using namespace std;
int res = 0;
int dir[][2] = {0,1,1,0,-1,0,0,-1};
int vis[10][10];
bool check(int x,int y){
    return x >= 0 && x <= 5 && y >= 0 && y <= 5;
}


void dfs(int x,int y,int dep){
    if(x == 0 && y == 0 && dep <= 12){
        res ++;
        return ;
    }
    if(dep >= 12) return;
    vis[x][y] = 1;
    for(int i = 0 ; i < 4 ; i ++){
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if(check(xx,yy) && !vis[xx][yy]){
            dfs(xx,yy,dep+1);
        }
    }
    vis[x][y] = 0;
}

signed main(){
    dfs(0,1,1);
    cout<<res*2-2<<endl;
    return 0;
}

F

Ans:

在這裡插入程式碼片

H

Ans:

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int t;
    cin>>t;
    while(t--){
        int cntG[4],cntR[4],cntY[4];
        memset(cntR,0,sizeof(cntR));
        memset(cntG,0,sizeof(cntG));
        memset(cntY,0,sizeof(cntY));
        string s1,s2,s3;
        cin>>s1>>s2>>s3;
        for(int i = 0 ; i < 12 ; i ++){
            if(s1[i] == 'G') cntG[i%4] ++;
            if(s1[i] == 'R') cntR[i%4] ++;
            if(s1[i] == 'Y') cntY[i%4] ++;
        }
        for(int i = 0 ; i < 8 ; i ++){
            if(s2[i] == 'G') cntG[i%4] ++;
            if(s2[i] == 'R') cntR[i%4] ++;
            if(s2[i] == 'Y') cntY[i%4] ++;
        }
        for(int i = 0 ; i < 4 ; i ++){
            if(s3[i] == 'G') cntG[i%4] ++;
            if(s3[i] == 'R') cntR[i%4] ++;
            if(s3[i] == 'Y') cntY[i%4] ++;
        }
        int flag = 1;
        for(int i = 0 ; i < 4 ; i ++){
            if(cntG[i] == 3 && cntR[i] == 2 && cntY[i] == 1){
                ;
            }else{
                flag = 0;
            }
        }
        cout<<(flag ? "YES" : "NO")<<endl;
    }
    return 0;
}

相關文章