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;
}
相关推荐
weixin_3077791325 分钟前
GCC C++实现Matlab矩阵计算和数学函数功能
c++·算法
云边小贩31 分钟前
C++ STL学习 之 泛型编程
开发语言·c++·学习·类与对象
东方佑1 小时前
UniVoc:基于二维矩阵映射的多语言词汇表系统
人工智能·算法·矩阵
逐梦,无惧!1 小时前
MFC的使用——使用ChartCtrl绘制曲线
c++·mfc
汤永红1 小时前
week1-[分支结构]中位数
c++·算法·信睡奥赛
啊阿狸不会拉杆1 小时前
《算法导论》第 24 章 - 单源最短路径
开发语言·数据结构·c++·算法·php
热爱生活的猴子2 小时前
算法148. 排序链表
数据结构·算法·链表
孤独得猿2 小时前
Redis类型之Hash
redis·算法·哈希算法
এ᭄画画的北北2 小时前
力扣-5.最长回文子串
算法·leetcode
点云侠3 小时前
【2025最新版】PCL点云处理算法汇总(C++长期更新版)
c++·算法·计算机视觉·3d·可视化