日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 103 (Rated for Div. 2)A~E解题报告

發(fā)布時(shí)間:2024/7/5 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 103 (Rated for Div. 2)A~E解题报告 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Educational Codeforces Round 103 (Rated for Div. 2)

A. K-divisible Sum

原題信息

解題思路

AC代碼

#include <bits/stdc++.h> using namespace std;typedef long long LL; const int N = 100010;int main() {int t; cin >> t;while (t -- ){static LL n, k;scanf("%lld%lld", &n, &k);k = (n / k + (n % k != 0)) * k;// printf("N=%lld, k=%lld\n", n, k);cout << (k / n + (k % n != 0)) << endl;}return 0; }

B. Inflation

原題信息

解題思路

AC代碼

#include <bits/stdc++.h> using namespace std;typedef long long LL; const int N = 100010; int n, k; LL p[N], b[N];int main() {int t; cin >> t;while (t -- ){scanf("%d%d", &n, &k);for (int i = 0; i < n; i ++ )scanf("%lld", &p[i]);b[0] = p[0];for (int i = 1; i < n; i ++ )b[i] = b[i - 1] + p[i];LL res = 0;for (int i = 1; i < n; i ++ ){res = max(res, 100LL * p[i] / k - b[i - 1] + (100LL * p[i] % k != 0));}cout << res << endl;}return 0; }

C. Longest Simple Cycle

原題信息

解題思路

AC代碼

#include <bits/stdc++.h> using namespace std;typedef long long LL; const int N = 100010; const LL INF = 0x3f3f3f3f3f3f3f3f; int n, k; LL res; LL a[N], b[N], c[N];int main() {int t; cin >> t;while (t -- ){res = 0;// inputscanf("%d", &n);for (int i = 1; i <= n; i ++ ) scanf("%lld", &c[i]);for (int i = 1; i <= n; i ++ ) scanf("%lld", &a[i]);for (int i = 1; i <= n; i ++ ) scanf("%lld", &b[i]);for (int i = 1; i <= n; i ++ )if (a[i] > b[i])swap(a[i], b[i]);LL tmp, pre = -INF;for (int i = 2; i <= n; i ++ ){if (a[i] == b[i])tmp = c[i] + 1;elsetmp = max(c[i] + b[i] - a[i] + 1, c[i] + pre - (b[i] - a[i] - 1));res = max(res, tmp);pre = tmp;}cout << res << endl;}return 0; }

D. Journey

原題信息

解題思路

AC代碼

#include <bits/stdc++.h> using namespace std;const int N = 301010; int f_l[N], f_r[N]; int ans[N]; char s[N]; int n;int main() {int t; cin >> t;while (t -- ){scanf("%d", &n);scanf("%s", s + 1);// leftf_l[1] = 1;for (int i = 2; i <= n; i ++ )if (s[i] != s[i - 1])f_l[i] = f_l[i - 1] + 1;elsef_l[i] = 1;// rightf_r[n] = 1;for (int i = n - 1; i >= 1; i -- )if (s[i] != s[i + 1])f_r[i] = f_r[i + 1] + 1;elsef_r[i] = 1;// 初始化并計(jì)算結(jié)果memset(ans, 0, sizeof ans);for (int i = 1; i <= n; i ++ )if (s[i] == 'R')ans[i - 1] += f_r[i];elseans[i] += f_l[i];cout << ans[0] + 1;for (int i = 1; i <= n; i ++ )printf(" %d", ans[i] + 1);puts("\n");}return 0; }

E. Pattern Matching

原題信息



解題思路


倘若題目的要求,變一下,變成 rearrange 后的 pattern 在 mt[j] 的位置上是與 str[j] 匹配的,那么本題就變成了一個(gè) 二分圖匈牙利算法的問題
顯示對 m 個(gè) str進(jìn)行排序,按照他們的 mt進(jìn)行排序,最后看每個(gè)mt需要滿足的匹配要求,連向可以連接的 pattern,這樣二分圖就構(gòu)建完成,直接跑一邊匈牙利算法即可。
這是我之前一直讀錯(cuò)的題意 ,絕了。

AC代碼

#include <bits/stdc++.h> using namespace std;const int BASE = 27, M = 27 * 27 * 27 * 27 + 10; const int N = 100010, K = 7; int _hash[M], char_num[258]; // _hash 需要開辟的數(shù)組 int n, m, k; char _str[N][K]; // n 個(gè) pattern char pattern_match[K]; // dfs查詢 m 個(gè) str可以匹配的 pattern 可能 char str[5]; int mt; // m 個(gè)詢問 vector<int> idx_ret; // 記錄返回的編號(hào) int h[N], e[M * 5], ne[M * 5], idx; bool flag = true; // 全局變量,記錄是否可以 int ind[N]; int res[N]; // 存儲(chǔ)最終的排序結(jié)果// 計(jì)算字符串hash的數(shù)值 int Cal(char *s) {int ret = 0;for (int i = 0, base = 1; i < k; i ++, s ++){ret += base * char_num[*s];base = base * BASE;}return ret; }// 第一個(gè)是 str, 第二個(gè)是 pattern,可以帶有_ bool Match(char *s, char *pa) {for (int i = 0; i < k; i ++ ){if (*s == *pa || *pa == '_' || *s == '_'){s ++; pa ++;continue;}return false;}return true; }void GetIdx(char *s, int cnt) {if (cnt == k){if (Match(str, pattern_match)){if (_hash[Cal(pattern_match)] != -1){idx_ret.push_back(_hash[Cal(pattern_match)]);}}return;}else{pattern_match[cnt] = *s;GetIdx(s + 1, cnt + 1);pattern_match[cnt] = '_';GetIdx(s + 1, cnt + 1);} }void add(int x, int y) {e[idx] = y, ne[idx] = h[x], h[x] = idx ++; }void topsort() {int cur_idx = 1;queue<int> que;for (int i = 1; i <= n; i ++ ){if (ind[i] == 0)que.push(i);}int u, v;/// printf("TOPSORT:\n");while (que.size()){u = que.front(); que.pop();res[cur_idx ++] = u;/// printf("%d, ", u);for (int i = h[u]; ~i; i = ne[i]){v = e[i];ind[v] --;if (ind[v] == 0)que.push(v);}}/// cout << endl;/// printf("n=%d, curidx=%d\n", n, cur_idx);flag = (cur_idx == n + 1);/// cout << flag << endl; }int main() {// _hash initialmemset(_hash, -1, sizeof _hash);for (int i = 'a'; i <= 'z'; i ++ )char_num[i] = i - 'a';char_num['_'] = 26;// edge list initialmemset(h, -1, sizeof h);idx = 1;// input and build string hashcin >> n >> m >> k;for (int i = 1; i <= n; i ++ ){scanf("%s", _str[i]);_hash[Cal(_str[i])] = i;} /*cout << 27 * 27 * 27 * 27 - 1 << endl;cout << Cal("abc_") << endl;cout << Cal("____") << endl;cout << Cal("aaaa") << endl;return 0; */// ind initialmemset(ind, 0, sizeof ind);for (int i = 1; flag && i <= m; i ++ ){scanf("%s%d", str, &mt);if (!Match(str, _str[mt])){puts("NO");return 0;}else{idx_ret.clear();GetIdx(str, 0);/// printf("\t*J:%d\n", i);for (int j = 0; flag && j < idx_ret.size(); j ++){if (mt != idx_ret[j]){add(mt, idx_ret[j]);ind[idx_ret[j]] ++;}/// cout << idx_ret[j] << ", ";}/// puts("");}}//if (!flag){/// printf("BEGIN\n");puts("NO");}else{topsort();if (!flag){puts("NO");}else{puts("YES");cout << res[1];for (int i = 2; i <= n; i ++ )printf(" %d", res[i]);puts("");}}return 0; }

賽后總結(jié)

題意一定要讀清楚,結(jié)合樣例好好看一看

輸入輸出的形式搞明白

結(jié)合建圖、貪心、動(dòng)態(tài)對話進(jìn)行綜合答題

總結(jié)

以上是生活随笔為你收集整理的Educational Codeforces Round 103 (Rated for Div. 2)A~E解题报告的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。