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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #533 (Div. 2)题解

發(fā)布時間:2024/10/12 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #533 (Div. 2)题解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

link

orz olinr AK Codeforces Round #533 (Div. 2)

中文水平和英文水平都太渣..翻譯不準確見諒

T1.給定n<=1000個整數(shù),你需要欽定一個值t,使得每個整數(shù)到線段[t-1,t+1]距離和最小,求最小距離,每個數(shù)<=100

枚舉t

#include <cstdio> using namespace std;int n, a[1010];int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) scanf("%d", &a[i]);int minans = 0x3f3f3f3f, fuck = -233;for (int ans = 1; ans <= 100; ans++){int cost = 0;for (int i = 1; i <= n; i++){if (a[i] > ans)cost += a[i] - ans - 1;else if (a[i] < ans)cost += ans - a[i] - 1;}if (cost < minans){minans = cost;fuck = ans;}}printf("%d %d\n", fuck, minans);return 0; }

T2.給定長度為n<=1e5的字符串s和一個數(shù)k<=1e5,要求求出一個最大的x,使得字符串中出現(xiàn)x個相同的不重疊的子串,每個子串內(nèi)只含有一種字符

枚舉每段連續(xù)區(qū)間,開桶記錄個數(shù) 注意循環(huán)完畢字符最后還要算下答案(代碼里直接多循環(huán)了一次處理)

#include <cstdio> using namespace std;int bucket[30]; char s[200010]; int n, k;int main() {scanf("%d%d", &n, &k);scanf("%s", s);char lastch = 0;int len = 0;for (int i = 0; i == 0 || s[i - 1] != 0; i++){if (s[i] == lastch)len++;else{if (lastch != 0)bucket[lastch - 96] += len / k;len = 1;lastch = s[i];}}int ans = 0;for (int i = 1; i <= 26; i++)if (ans < bucket[i])ans = bucket[i];printf("%d\n", ans);return 0; }

T3.求長度為n,數(shù)組里每個元素在[l,r]之間并且元素和%3=0的數(shù)組數(shù)量%1e9+7 n<=2e5,l<=r<=1e9

處理出[l,r]內(nèi)%3=0,1,2的數(shù)字數(shù)量,然后無腦dp

#include <cstdio> #include <iostream> using namespace std;int n, l, r, p = 1000000007; int cnt[3]; long long f[200010][3];int main() {scanf("%d%d%d", &n, &l, &r), l--;cnt[0] = (r + 3) / 3 - (l + 3) / 3;cnt[1] = (r + 2) / 3 - (l + 2) / 3;cnt[2] = (r + 1) / 3 - (l + 1) / 3;f[0][0] = 1;for (int i = 1; i <= n; i++){for (int now = 0; now <= 2; now++){for (int last = 0; last <= 2; last++){int dis = (now - last) % 3;if (dis < 0) dis += 3;f[i][now] += f[i - 1][last] * cnt[dis] % p;f[i][now] %= p;}}}cout << f[n][0] << endl;return 0; }

T4.N*M(N<=1000,M<=1000)的棋盤上Van一個游戲,一共p<=9個人,每個人有個速度si,每次每個人將他棋盤上所有棋子能走<=si步的所有位置都放上棋子,要求不能經(jīng)過墻和別的玩家的棋子

bfs套bfs?第一層bfs維護每個玩家的等待擴展的棋子隊列,第二層bfs在每個玩家擴展棋子時候維護,對第二層bfs擴展到距離為si的位置加入第一層bfs的隊列即可(因為只有他們才能繼續(xù)擴展)

代碼略長

#include <bits/stdc++.h> using namespace std;int n, m, p, s[15]; int mp[1010][1010]; int dis[1010][1010];int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0};int main() {scanf("%d%d%d", &n, &m, &p);for (int i = 1; i <= p; i++) scanf("%d", &s[i]);for (int i = 1; i <= n; i++)mp[i][0] = mp[i][m + 1] = -1;for (int j = 1; j <= m; j++)mp[0][j] = mp[n + 1][j] = -1;for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){char s;scanf(" %c", &s);if (s == '#')mp[i][j] = -1;if (s >= '1' && s <= '9')mp[i][j] = s - 48;}}queue<int> qx, qy;for (int pl = 1; pl <= p; pl++){for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){if (mp[i][j] == pl){qx.push(i), qy.push(j);}}}}while (!qx.empty()){int x = qx.front(), y = qy.front();qx.pop(), qy.pop();int col = mp[x][y];queue<int> qx1, qy1;dis[x][y] = 0;qx1.push(x), qy1.push(y);while (!qx1.empty()){int x1 = qx1.front(), y1 = qy1.front();qx1.pop(), qy1.pop();for (int d = 0; d < 4; d++){int nx = x1 + dx[d], ny = y1 + dy[d];if (mp[nx][ny] != 0) continue;mp[nx][ny] = col;dis[nx][ny] = dis[x1][y1] + 1;if (dis[nx][ny] == s[col]){qx.push(nx), qy.push(ny);}elseqx1.push(nx), qy1.push(ny);}}}int ans[13];memset(ans, 0, sizeof(ans));for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)if (mp[i][j] > 0)ans[mp[i][j]]++;for (int i = 1; i <= p; i++)printf("%d ", ans[i]);return 0; }

做題時候變量名寫錯了WA了一發(fā)。。。

T5.你有一個長度為n(n<=1e5)的事件序列,包含兩種事件:1.你可以修改你的社交賬戶名(修改為你的m個朋友之一 m<=40)2.朋友s訪問你的社交賬戶。如果一個朋友是高興的,當且僅當每次他訪問你時候你的社交用戶名都是他的名字。最大化高興的朋友的數(shù)量

將兩個事件1之間的所有事件2定義為一個區(qū)間,那么這個區(qū)間內(nèi)所有朋友是互斥的,即這些朋友最多有一個是高興的,那么我們可以構建無向圖,每個區(qū)間內(nèi)所有朋友兩兩連邊,最后求最大獨立集,可以轉化為最大團(其實他倆差不多)

由于m<=40,所以不能枚舉集合,官方題解給出了meet in the middle做法,不過這種最大團都可以被隨機序列怒艸。。。

#include <bits/stdc++.h> using namespace std;bool vis[50][50]; int n, tot; map<string, int> id;bool in[50]; int seq[50];bool valid(int x) {for (int j = 1; j <= n; j++)if (in[j] == true && vis[j][x] == true) return false;return true; }int work() {int cnt = 0;memset(in, 0, sizeof(in));for (int i = 1; i <= n; i++)if (valid(seq[i])) in[seq[i]] = true, cnt++;return cnt; }void clean() {for (int i = 1; i <= n; i++)if (in[i] == true)for (int j = 1; j <= n; j++)if (in[j] == true)vis[i][j] = true;memset(in, 0, sizeof(in)); }int main() {int cnt;srand(time(0));scanf("%d%d", &cnt, &n);for (int i = 1; i <= cnt; i++){int opd;scanf("%d", &opd);if (opd == 1) clean();else{string name;cin >> name;if (id.count(name) == false) id[name] = ++tot;in[id[name]] = true;}}clean();for (int i = 1; i <= n; i++) seq[i] = i;int ans = 0, t = 100000;while (clock() / (double)CLOCKS_PER_SEC <= 1.95){random_shuffle(seq + 1, seq + 1 + n);ans = max(ans, work());}printf("%d\n", ans);return 0; }

學校太操蛋,9點55放學,10點10分睡覺,沒時間打CF

這次終于有個時間合適的比賽了

第一次打CF,網(wǎng)太卡沒hack,最后rating就漲了201,感覺一般般,還是因為自己太菜

前40分鐘之內(nèi)切掉了前4題,然后第五題題意沒讀懂,問出題人,出題人給回了句原題中的話,給一個詞加了粗,然后懂了,懂了后轉化出最大團的模型,就是不會做

忘了有個東西叫meet in the middle,也忘了有個東西叫隨機化,這就非常cd了

由于學校太操蛋,以后在線打CF的機會肯定不多

打CF主要是練手速和一遍A,畢竟一遍不A扣50分也很惡心的。。。比如說這次B和D都沒一遍A

轉載于:https://www.cnblogs.com/oier/p/10300593.html

總結

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

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