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;
}
相关推荐
Navigator_Z几秒前
LeetCode //C - 1300. Sum of Mutated Array Closest to Target
c语言·算法·leetcode
SZYSK2 分钟前
鸿蒙人脸识别算法放在终端里:和外挂授权 SDK 差在排障路径
物联网·算法·华为·harmonyos
凯瑟琳.奥古斯特30 分钟前
力扣1016高效解法:剪枝优化技巧
开发语言·c++·算法·leetcode·职场和发展
xiangyun611 小时前
C++ priority_queue 底层:手撕二叉堆与 Top K 问题
c++·算法·面试·stl·1024程序员节
坤坤子吖1 小时前
C++继承:友元、静态成员、多继承与组合
开发语言·c++·笔记·学习·1024程序员节
qz_Serene2 小时前
练习算法题:双指针 -cpp
c++·算法·leetcode·1024程序员节
扶尔魔ocy2 小时前
【C++开发】从裸指针到智能指针
c++·智能指针·1024程序员节
Nuanyt2 小时前
Hot 100 刷题笔记 · 数组与哈希专题(3 题)
java·笔记·算法·leetcode·哈希算法·1024程序员节
碧海银沙音频科技研究院3 小时前
基于炬芯平台ATS308X多模型兼容语音识别算法
人工智能·算法·语音识别
爱读书的小胖3 小时前
LeetCode 274 H 指数 C 语言解题分析
c语言·算法·leetcode·1024程序员节