第十五届蓝桥杯第三场模拟赛

第一题: 我的答案:6

#include <iostream>
using namespace std;
int main(){
    int ans = 0;
    for(int i =1;i<=2023;i++){
        if(2023%i == 0){
            ans ++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

第二题  我的答案:4186

#include <iostream>
using namespace std;
int main(){
    int ans = 0;
    for(int l = 0;l<=100;l++){
        for(int r = 0;r<=100;r++){
            if(l-r >=10){
                ans ++;
            }
        }    
    }
    
    cout << ans << endl;
    return 0;
}

第三题  我的答案:5503

#include <iostream>
using namespace std;
int getSum(int num){
    int sum = 0;
    while(num > 0){
        sum += num%10;
        num/=10;
    }
    return sum;
}
bool isPrime(int num){
    for(int i = 2;i<=num-1;i++){
        if(num%i == 0)return false; 
    }
    return true;
}
int main(){
    int ans = 0;
    //cout << getSum(599) << endl;
    for(int i = 1;i<=1000000;i++){
        if(i == 5e5){cout << 5 << endl;
        }
        if(i == 3e5){cout << 5 << endl;
        }
        if(i == 8e5){cout << 5 << endl;
        }
        
        if(isPrime(i)){
            if(getSum(i) == 23){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

第四题   我的答案:344

#include <iostream>
using namespace std;

int main(){
    //1234567890 * 5
    int n = 1234567890;
    int a1 = n%2023;
    int a2 = ((((n%2023) * 100000)%2023) * 100000)%2023;
    int a3 = ((((((((n%2023) * 100000)%2023) * 100000)%2023) * 100000)%2023) * 100000) %2023;
    int a4 = ((((((((((((n%2023) * 100000)%2023) * 100000)%2023) * 100000)%2023) * 100000) %2023) * 100000)%2023) * 100000) %2023;
    int a5 = ((((((((((((((((n%2023) * 100000)%2023) * 100000)%2023) * 100000)%2023) * 100000) %2023) * 100000)%2023) * 100000) %2023) * 100000)%2023) * 100000) %2023;
    cout << (a1+a2+a3+a4+a5)%2023 << endl;
    return 0;
}

第五题 我的答案: 171248

#include <iostream>
#include <queue>
#include<fstream>
using namespace std;
int n = 30;
int m = 20;
int a[35][35];
int b[35][35];
int main(){
    fstream f;
    f.open("aaaaaaaaa.txt",ios::in);
    
    
    
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            f >> a[i][j];
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << a[30][20] << endl;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            a[i][j] += a[i][j-1];//左右压缩 
        }
    }
    
    for(int j = 1;j<=m;j++){
        for(int i = 1;i<=n;i++){
            a[i][j] += a[i-1][j];//上下压缩 
        }
    }
    int ans = 0;
    int xxxx = 5;
    for(int i = xxxx;i<=n;i++){
        for(int j = xxxx;j<=m;j++){
            int sum = a[i][j] - a[i][j-xxxx] - a[i-xxxx][j] + a[i-xxxx][j-xxxx];
            ans = max(ans,sum);
        }
    } 
    cout << ans << endl;
    return 0;
}

第六题

 #include <iostream>
using namespace std;
int n;//1e4
int f[10005];
int main(){
    cin >> n;
    int first = n/3;
    int left = n%3;
    if(left == 0){
        cout << first;
        return 0;
    }else{
        cout << first + 1;
    }
    return 0;
}

第七题

#include <iostream>
using namespace std;
int n;//1e4
int f[10005];
int main(){
    string a;
    cin >> a;
    int ans = 0; 
    for(int i = 0;i<a.length();i++){
        int b = a[i] - 48;
        if(b%2 != 0){
            //为奇
            ans++; 
        }
    }
    cout << ans << endl;
    return 0;
}

第八题

#include <iostream>
using namespace std;
int n;//1e3
int a[1005];
int main(){
    cin >> n;
    for(int i = 1;i<=n;i++){
        cin >> a[i];
    }
    int minN = -1;
    int maxN = 1e9;
    for(int i = 2;i<=n-1;i++){
        if(a[i] < a[i-1] && a[i] < a[i+1]){
            minN = max(minN,a[i]);
        }
        if(a[i] > a[i-1] && a[i] > a[i+1]){
            maxN = min(maxN,a[i]);
        }
    }
    cout << minN << " " << maxN << endl;
    return 0;
}

第九题

#include <iostream>
#include <queue>
using namespace std;
int n,m;//1000  1e3
typedef pair<int,int> PII;

struct node{
    int x;
    int y;
    int state;//0中点  1下方 2 左上角 3 右上角
};
queue<node> q;
char mappp[1005][1005];
int dy[] = {0,0,-1,1};
int dx[] = {0,1,-1,-1};
bool haveAns = false;
int allL = -1;
void bfs(int x,int y){
    while(!q.empty()){
        q.pop();
    }
    q.push({x,y,0});
    int length1 = 0;
    int length2 = 0;
    int length3 = 0;

    while(!q.empty()){
        auto t = q.front();
        q.pop();
        //中点 
        if(t.state == 0){
            //cout << "here" << endl;
            for(int i = 1;i<=3;i++){
                int newX = t.x + dx[i];
                int newY = t.y + dy[i];
                //cout << "newX = " << newX << " newY = " << newY << endl;
                if(mappp[newX][newY] == mappp[t.x][t.y]){
                    q.push({newX,newY,i});
                }else{
                    return;//如果中点四周有一个不行 
                }
            }//如果中点四周都可行 
            length1 = 1;
            length2 = 1;
            length3 = 1;
            //三边长度设置为1 
            haveAns = true;//必定有答案    
            continue; 
        }
        //中点 
        
        //下方 
        if(t.state == 1){
            int newX = t.x + dx[t.state];
            int newY = t.y + dy[t.state];
            if(newX <= 0 || newY <= 0 || newX > n || newY > m){
                allL = max(length1,allL);
                return; 
            }
            if(mappp[newX][newY] == mappp[t.x][t.y]){
                q.push({newX,newY,t.state});
            }else{
                allL = max(length1,allL);
                return;//结束BFS 返回三边 
            }
            length1++;
            continue;
        }
        //下方 
        
        //左上 
        if(t.state == 2){
            int newX = t.x + dx[t.state];
            int newY = t.y + dy[t.state];
            if(newX <= 0 || newY <= 0 || newX > n || newY > m){
                allL = max(length2,allL);
                return;
            }
            if(mappp[newX][newY] == mappp[t.x][t.y]){
                q.push({newX,newY,t.state});
            }else{
                allL = max(length2,allL);
                return;
            }
            length2++;
            continue;
        }
        //左上
        
        
        //右上 
        if(t.state == 3){
            int newX = t.x + dx[t.state];
            int newY = t.y + dy[t.state];
            if(newX <= 0 || newY <= 0 || newX > n || newY > m){
                allL = max(length3,allL);
                return;
            }
            if(mappp[newX][newY] == mappp[t.x][t.y]){
                q.push({newX,newY,t.state});
            }else{
                allL = max(length3,allL);
                return;
            }
            length3++;
            continue;
        }
        //右上
        
    }
    
}
int main(){
    cin >> n >> m;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            cin >>mappp[i][j];
        }
    }
    bfs(4,4);
//    for(int i = 2;i<=n-1;i++){
//        for(int j = 2;j<=m-1;j++){
//            bfs(i,j);
//        }
//    }
    if(!haveAns){
        cout << 0 << endl;
    }else{
        cout << allL << endl;
    }
    return 0;
}

第十题

#include <iostream>
#include <queue>
using namespace std;
int n;
int a,b,c;
int f[55];
int main(){
    cin >> n;//50
    cin >> a >> b >> c;// 1e6
    f[a] = 1;
    f[b] = 1;
    f[c] = 1;
    for(int i = a;i<=c;i++){
        f[i] += f[i-a];
        if(i-b >=0){
            f[i] += f[i-b];
        }
        if(i-c >= 0){
            f[i] += f[i-c];        
        }
    }
    for(int i = c+1;i<=n;i++){
        f[i] = f[i-a] + f[i-b] + f[i-c];
    }
    cout << f[n] << endl;
    return 0;
}

  • 14
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值