本文主要是介绍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)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!