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;
}
相关推荐
木子.李3472 小时前
排序算法总结(C++)
c++·算法·排序算法
闪电麦坤953 小时前
数据结构:递归的种类(Types of Recursion)
数据结构·算法
freyazzr3 小时前
C++八股 | Day2 | atom/函数指针/指针函数/struct、Class/静态局部变量、局部变量、全局变量/强制类型转换
c++
Gyoku Mint4 小时前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
纪元A梦4 小时前
分布式拜占庭容错算法——PBFT算法深度解析
java·分布式·算法
fpcc4 小时前
跟我学c++中级篇——理解类型推导和C++不同版本的支持
开发语言·c++
px不是xp4 小时前
山东大学算法设计与分析复习笔记
笔记·算法·贪心算法·动态规划·图搜索算法
终焉代码5 小时前
STL解析——list的使用
开发语言·c++
DevangLic5 小时前
【 *p取出内容 &a得到地址】
c++