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;
}
相关推荐
卿卿qing2 分钟前
【JavaScript】算法之贪心算法(贪婪算法)
算法
郭小儒9 分钟前
VCNet论文阅读笔记
算法
归寻太乙14 分钟前
C++函数重载完成日期类相关计算
开发语言·c++
尽蝶叙17 分钟前
C++:分苹果【排列组合】
开发语言·c++·算法
所待.38323 分钟前
小小扑克牌算法
java·算法
憧憬成为原神糕手42 分钟前
c++_list
开发语言·c++
zyh2005043044 分钟前
c++的decltype关键字
c++·decltype
眰恦3741 小时前
数据结构--第六章图
数据结构·算法
2401_862886781 小时前
蓝禾,汤臣倍健,三七互娱,得物,顺丰,快手,游卡,oppo,康冠科技,途游游戏,埃科光电25秋招内推
前端·c++·python·算法·游戏