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;
}
相关推荐
努力努力再努力wz5 分钟前
【c++进阶系列】:万字详解AVL树(附源码实现)
java·运维·开发语言·c++·redis
Miraitowa_cheems13 分钟前
LeetCode算法日记 - Day 34: 二进制求和、字符串相乘
java·算法·leetcode·链表·职场和发展
wan5555cn25 分钟前
AI生成内容的版权问题解析与实操指南
人工智能·笔记·深度学习·算法·音视频
小张成长计划..30 分钟前
C++基础知识
c++
CHANG_THE_WORLD31 分钟前
C++并发编程指南 std::promise 介绍与使用
java·开发语言·c++·promise
DDAshley1262 小时前
【PaddleOCR】从零开始训练自己的模型--详细教程
算法·计算机视觉
梁辰兴2 小时前
数据结构:查找
数据结构·算法·查找·顺序查找·折半查找·分块查找
Brookty2 小时前
【算法】双指针(一)移动零
学习·算法
天天代码码天天2 小时前
C++ opencv RTSP小工具 RTSP流播放、每一帧保存
开发语言·c++·opencv