ccfcsp-202209(1、2、3)

2024-09-06 13:52
文章标签 ccfcsp 202209

本文主要是介绍ccfcsp-202209(1、2、3),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

202209-1 如此编码

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m;cin >> n >> m;vector<ll> a(n,0);vector<ll> b(n,0);for(int i = 0;i < n;i++){cin >> a[i];}ll temp,t = 1;for(int i = 0; i < n; i++){temp = t;t *= a[i];//计算m除以c的余数,然后减去m除以temp的余数,最后再除以tempb[i] = ((m % t) - (m % temp)) / temp;}for(int i = 0; i < n; i++){cout << b[i] << " ";}return 0;
}

202209-2 何以包邮?

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;const int N = 31, M = 3e5 + 1; // 因n不超过30,总价的关系300001
int price[N];
ll dp[N][M];//前i本书放入总价为j的背包中所获得的最大价值int main() {int n, x; // n为购物车中图书数量,x为包邮价格条件cin >> n >> x;ll sum = 0; // 最大价格for (int i = 1; i <= n; i++) {cin >> price[i];sum = sum + price[i];}ll res = sum; //满足条件的最低价格for(int i = 1; i <= n; i++){//遍历书for(int j = 1; j <= sum; j++){//遍历总价if(price[i] <= j){dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - price[i]] + price[i]);}else{dp[i][j] = dp[i - 1][j];}if(x <= dp[i][j] && dp[i][j] < res){ // 找到满足条件且最低的总价格res = dp[i][j];}}}cout << res;return 0;
}

202209-3 防疫大数据

40分解

#include <bits/stdc++.h>
using namespace std;unordered_map<int,int> region;//风险地区,记录i地何时开始进入风险
map<int,int> user;//风险名单int main() {int n;cin >> n;int r, m;for(int i = 0; i < n; i++){cin >> r >> m;for(int j = 0; j < r; j++){int area;cin >> area;region[area] = i;}cout << i << " ";for(int j = 0; j < m; j++){int d,u,r0;//d日期、u用户、r0到访地区cin >> d >> u >> r0;if(region.find(r0) != region.end()){if(region[r0] <= d && region[r0] > d - 7){user[u] = 7 + region[r0] - i;}}}for(auto it = user.begin(); it != user.end(); ++it){if(it->second > 0){cout << it->first << " ";it->second--;}}cout << endl;}return 0;
}

这篇关于ccfcsp-202209(1、2、3)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1142186

相关文章

ccfcsp-202206(1、2、3)

202206-1 归一化处理 #include <bits/stdc++.h>using namespace std;int main() {int n;cin >> n;vector<double> vec(n);double ave = 0;for(int i = 0; i < n; i++){cin >> vec[i];ave += vec[i];}ave /= n;double va

ccfcsp-202212(1、2、3)

202212-1 现值计算 #include <bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;double i;cin >> n >> i;vector<double> money(n + 1);double res = 0;for(in

ccfcsp-202305(1、2、3)

202305-1 重复局面 #include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;unordered_map<string, int> mp;string str, s;while(n--){str = "

202209青少年软件编程(Python)等级考试试卷(二级)

第 1 题 【单选题】 下列语句中变量 i 取值范围是 1~10 的是? ( ) A :for i in range(11) B :for i in range(1, 10) C :for i in range(0, 10) D :for i in range(1, 11) 正确答案:D 试题解析: 第 2 题 【单选题】 运行以下代码, 结果输出的是? ( ) means=[

CCF-Csp算法能力认证,202209-1如此编码(C++)含解析

前言 推荐书目,在这里推荐那一本《算法笔记》(胡明),需要PDF的话,链接如下 「链接:https://pan.xunlei.com/s/VNvz4BUFYqnx8kJ4BI4v1ywPA1?pwd=6vdq# 提取码:6vdq”复制这段内容后打开手机迅雷App,查看更方便」 希望有大神能够提供改良意见,敬礼! -------------------------------------

2024 ccfcsp认证打卡 2022 12 01 现值计算

import java.util.Scanner;public class FinancialFormula {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);final int N = 1010; // 定义数组大小int n = scanner.nextInt(); //

2024 ccfcsp认证打卡 2023 03 02 垦田计划

import java.util.*;public class Main {public static void main(String[] args) {Scanner input = new Scanner(System.in);int N = 100100; // 定义一个较大的常数Nlong[] t = new long[N]; // 存储任务的耗时long[] c = new l

2024 ccfcsp认证打卡 2023 09 02 坐标变换(其二)

202309-2 坐标变换(其二) 题解1题解2区别第一种算法(使用ArrayList存储操作序列):数据结构:操作序列处理: 第二种算法(使用两个数组存储累积结果):数据结构:操作序列处理: 对比效率简洁性可读性 题解1 import java.util.ArrayList;import java.util.Scanner;public class Main {pu

【CSP试题回顾】202209-2-何以包邮?(优化)

CSP-202209-2-何以包邮? 解题代码 #include <iostream>#include <set>using namespace std;int n, x, a;set<int>MySet;int main() {cin >> n >> x;for (size_t i = 0; i < n; i++){cin >> a;set<int>SetTemp;for (auto&

B3660 [语言月赛202209] 集卡

题目背景 小 A 最近迷上了集卡。 题目描述 小 A 最近买了 T 次卡牌,每次买了 n 张(注意,不同次买的卡牌数量不一定相同)。每张卡都有一个数字编号,如果编号是 0 则代表抽到了隐藏款。 小 A 想分别知道每次购买的卡牌中,是否抽到了隐藏款。如果抽到了则输出 yes,否则输出 no。 输入格式 第一行,一个整数 T,表示小 A 最近买了 T 次卡牌。 接下来包含 2T 行数据,