ccfcsp-202006(4、5)

202006-4 1246

32分解

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    string str1 = "1";
    for(int i = 0; i < n; i++){
        string str2 = "";
        for(int j = 0; j < str1.size(); j++){
            if(str1[j] == '1')
                str2 += '2';
            if(str1[j] == '2')
                str2 += '4';
            if(str1[j] == '4')
                str2 += "16";
            if(str1[j] == '6')
                str2 += "64";
        }
        str1 = str2;
    }
    int res = 0;
    int pos = 0;
    while(str1.find(s, pos) != -1){
        res++;
        pos = str1.find(s, pos) + 1;
    }
    cout << res;
    return 0;
}

202006-5 乔乔和牛牛逛超市

80分解

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int a[n][5], b[m][3];
    long long Max[n], res = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        Max[i] = a[i][0] * a[i][0] * a[i][2] + a[i][0] * a[i][3] + a[i][4];
        for(int j = a[i][0]; j <= a[i][1]; j++){
            if(j * j * a[i][2] + j * a[i][3] + a[i][4] > Max[i]){
                Max[i] = j * j * a[i][2] + j * a[i][3] + a[i][4];
            }
        }
    }
    for(int i = 0; i< n;i++){
        res += Max[i];
    }
    cout << res;
    return 0;
}
相关推荐
haibindev11 分钟前
把近5万个源文件喂给AI之前,我先做了一件事
java·前端·c++·ai编程·代码审计·架构分析
xushichao198925 分钟前
C++中的中介者模式
开发语言·c++·算法
MORE_7727 分钟前
leecode100-买卖股票的最佳时期-贪心算法
python·算法·贪心算法
AI科技星31 分钟前
基于wr/c + h/c = 1的螺旋线矢量特性及应用分析
c语言·开发语言·人工智能·opencv·算法·计算机视觉·r语言
颜酱34 分钟前
回溯算法专项突破练习(1)
javascript·后端·算法
进击的荆棘42 分钟前
优选算法——分治
数据结构·算法·leetcode·分治
是娇娇公主~43 分钟前
C++ 多态机制与虚函数实现原理(补充)
c语言·c++
Yupureki1 小时前
《实战项目-个人在线OJ平台》1.项目简介和演示
c语言·数据结构·c++·sql·算法·性能优化·html5
无敌秋1 小时前
C++ public, private, protected类的继承
开发语言·c++
m0_579393661 小时前
C++代码混淆与保护
开发语言·c++·算法