本文主要是介绍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 = "";for(int i = 0; i < 8; i++){cin >> s;str += s;}mp[str]++;cout << mp[str] << endl;}return 0;
}
202305-2 矩阵运算
需要注意调整矩阵乘的顺序,降低时间复杂度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;int main() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll n, d;cin >> n >> d;vector<vector<ll>> Q(n, vector<ll>(d));vector<vector<ll>> Kt(d, vector<ll>(n));vector<vector<ll>> V(n, vector<ll>(d));vector<int> W(n);for(int i = 0; i < n; i++){for(int j = 0; j < d; j++){cin >> Q[i][j];}}for(int i = 0; i < n; i++){for(int j = 0; j < d; j++){cin >> Kt[j][i];}}for(int i = 0; i < n; i++){for(int j = 0; j < d; j++){cin >> V[i][j];}}for(int i = 0; i < n; i++)cin >> W[i];//先算K转置 * V,不然是 n*n*d 时间复杂度vector<vector<ll>> KtV(d, vector<ll>(d));for(int i = 0; i < d; i++){for(int j = 0; j < d; j++){for(int k = 0; k < n; k++){KtV[i][j] += Kt[i][k] * V[k][j];}}}//W * Qfor(int i = 0; i < n; i++){for(int j = 0; j < d; j++){Q[i][j] *= W[i];}}//Q * KtVvector<vector<ll>> res(n, vector<ll>(d));for(int i = 0; i < n; i++){for(int j = 0; j < d; j++){for(int k = 0; k < d; k++){res[i][j] += Q[i][k] * KtV[k][j];}}}for(int i = 0; i < n; i++){//Q * Kfor(int j = 0; j < d; j++){cout << res[i][j] << " ";}cout << endl;}return 0;
}
202305-3 解压缩
50分解
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;string str,res;
string Tobinary(char c){int i = isdigit(c) ? c - '0' : c - 'a' + 10;int n = i;string s = "";while(n){char t = n % 2 + '0';s = t + s;n /= 2;}while(s.size() < 4)s = '0' + s;return s;
}
ll Todecimal(string s){ll n = s.size();ll res = 0;for(ll i = n - 1; i >= 0; i--){res += (s[i] - '0') * pow(2, n - i - 1);}return res;
}
int main() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll n;cin >> n;string s;for(ll i = 0; i < n / 8 + 1; i++){cin >> s;str += s;}ll i = 0;//引导域string guide = "";for(; i + 1 < str.size() && str[i] >= '8'; i += 2){guide = guide + str[i] + str[i + 1];}guide = guide + str[i] + str[i + 1];i += 2;string s1, s2;for(; i < str.size(); i += 2){s1 = Tobinary(str[i]);s2 = Tobinary(str[i + 1]);if(s2[2] == '0' && s2[3] == '0'){//字面量s = s1 + s2[0] + s2[1];ll num = Todecimal(s) + 1;if(num >= 60){s.clear();ll j;for(j = i + 2; j < i + num - 57; j += 2){s = string(1,str[j]) + string(1,str[j + 1]) + s;}string ss;for(ll k = 0; k < s.size(); k++){ss += Tobinary(s[k]);}num = Todecimal(ss) + 1;i = j - 2;}for(ll j = i + 2; j < i + num * 2 + 2; j += 2){cout << str[j] << str[j + 1];res.push_back(str[j]);res.push_back(str[j + 1]);if(res.size() % 16 == 0)cout << endl;}i += num * 2;}else if(s2[2] == '1' && s2[3] == '0'){//回溯引用1s = s1 + s2[0] + s2[1];ll num = Todecimal(s) + 1;i += 2;s1 = string(1,str[i]) + string(1,str[i + 1]);//03s2 = string(1,str[i + 2]) + string(1,str[i + 3]);//00i += 4;string ss = s2 + s1;//小端ll o = Todecimal(ss);ll j = res.size()/2 - o;while(num--){cout << res[j * 2] << res[j * 2 + 1];res.push_back(res[j * 2]);res.push_back(res[j * 2 + 1]);if(res.size() % 16 == 0)cout << endl;j++;if(j == res.size())j = res.size()/2 - o;}i -= 2;}else if(s2[2] == '0' && s2[3] == '1'){//回溯引用2string sl = string(1,s1[3]) + string(1,s2[0]) + string(1,s2[1]);ll l = Todecimal(sl) + 4;string so = s1.substr(0,3);i += 2;so += Tobinary(str[i]) + Tobinary(str[i + 1]);ll o = Todecimal(so);ll j = res.size()/2 - o;while(l--){cout << res[j * 2] << res[j * 2 + 1];res.push_back(res[j * 2]);res.push_back(res[j * 2 + 1]);if(res.size() % 16 == 0)cout << endl;j++;if(j == res.size())j = res.size()/2 - o;}}}return 0;
}
这篇关于ccfcsp-202305(1、2、3)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!