本文主要是介绍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(int j = 0; j <= n; j++){cin >> money[j];res += money[j] / pow(1 + i, j);}cout << res;return 0;
}
202212-2 训练计划
#include <bits/stdc++.h>
using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, m;cin >> n >> m;vector<vector<int>> vec(m + 1, vector<int>(2,0));unordered_set<int> mset;for(int i = 1; i <= m; i++){cin >> vec[i][0];mset.insert(i);}for(int i = 1; i <= m; i++){cin >> vec[i][1];if(mset.find(vec[i][0]) != mset.end()){mset.erase(vec[i][0]);}}vector<int> early(m + 1, 0);//最早vector<int> late(m + 1, INT_MAX);//最晚for(int i = 1; i <= m; i++){int day = 1;int j = vec[i][0];while(j != 0){day += vec[j][1];j = vec[j][0];}early[i] = day;cout << day << " ";}cout << endl;for(auto it : mset){late[it] = n - vec[it][1] + 1;int i = it;int j = vec[it][0];//j为i的上一个节点while(j != 0){late[j] = min(late[j], late[i] - vec[j][1]);//可能有不同路径,所以要取最小值i = j;j = vec[j][0];}}int flag = 1;for(int i = 1; i <= m; i++){if(late[i] <= 0)flag = 0;}if(flag){for(int i = 1; i <= m; i++){cout << late[i] << " ";}}return 0;
}
202212-3 JPEG 解码
#include <bits/stdc++.h>
using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, T;vector<vector<int>> Q(8, vector<int>(8));vector<vector<int>> M(8, vector<int>(8, 0));vector<vector<int>> M1(8, vector<int>(8, 0));for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){cin >> Q[i][j];}}cin >> n >> T;vector<int> data(n);for(int i = 0; i < n; i++){cin >> data[i];}//读入扫描数据int k = 0;for(int i = 0; i < 15; i++){if(i % 2){for(int j = max(i - 7 , 0); j <= i && j < 8; j++){M[j][i - j] = data[k++];}}else{for(int j = min(i, 7); j >= 0 && i - j < 8; j--){M[j][i - j] = data[k++];}}if(k >= n)break;}//将矩阵M中的每个元素都乘以量化矩阵Q中的对应元素for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){Q[i][j] *= M[i][j];}}//对矩阵M进行离散余弦逆变换for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){double res = 0;for(int u = 0; u < 8; u++){for(int v = 0; v < 8; v++){double au = u == 0 ? sqrt(0.5) : 1;double av = v == 0 ? sqrt(0.5) : 1;res += au * av * Q[u][v] * cos((acos(-1) / 8.0) * (i + 0.5) * u) * cos((acos(-1) / 8.0) * (j + 0.5) * v);}}int t = round(res / 4 + 128);if(t > 255)t = 255;else if(t < 0)t = 0;M1[i][j] = t;}}if(T == 0){for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){cout << M[i][j] << " ";}cout << endl;}}else if(T == 1){for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){cout << Q[i][j] << " ";}cout << endl;}}else if(T == 2){for(int i = 0; i < 8; i++){for(int j = 0; j < 8; j++){cout << M1[i][j] << " ";}cout << endl;}}return 0;
}
这篇关于ccfcsp-202212(1、2、3)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!