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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

编程问答

Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

發(fā)布時(shí)間:2023/12/4 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Educational Codeforces Round 89 (Rated for Div. 2)

A. Shovels and Swords

思路

題意非常簡(jiǎn)單,就是得到最多的物品嘛,我們假定a,ba, ba,baaa是最小的一個(gè),分兩種情況。

如果2?a<=b2 * a <= b2?a<=b,那么我們只需要購(gòu)買(mǎi)花費(fèi)是1,21, 21,2的東西即可,也就是最后能購(gòu)買(mǎi)得到aaa件物品。

否則的話,我們一定是先讓數(shù)量更多的去減222,用數(shù)量更少的去減111,直到兩個(gè)物品的數(shù)量相等,再通過(guò)1,21, 21,22,12, 12,1的順序去交換執(zhí)行,總結(jié)一下最后的答案就是(n+m)/3(n + m) / 3(n+m)/3

代碼

#include <bits/stdc++.h> #define mp make_pair #define pb push_backusing namespace std;typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull;const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }const int N = 2e5 + 10;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {ll a = read(), b = read();if(a > b) swap(a, b);if(a * 2 <= b) printf("%lld\n", a);else printf("%lld\n", (a + b) / 3);}return 0; }

B.Shuffle

思路

就是一個(gè)區(qū)間有重合判斷并集的問(wèn)題,如果我們給定的區(qū)間[l,r][l, r][l,r]在原本的區(qū)間外也就是r<L∣∣l>Rr < L || l > Rr<Ll>R,否則的話我們就更新L,RL, RL,R的最大最小值

代碼

#include <bits/stdc++.h> #define mp make_pair #define pb push_backusing namespace std;typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull;const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }const int N = 2e5 + 10;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {int n = read(), x = read(), m = read();int l = x, r = x;// cout << l << " " << r << endl;for(int i = 1; i <= m; i++) {int a = read(), b = read();if((a <= r && a >= l) || (b >= l && b <= r) || (l >= a && b >= r)) {//比賽時(shí)判斷條件寫(xiě)的比較繁瑣。l = min(l, a);r = max(r, b);}// cout << l << " " << r << endl;}printf("%d\n", r - l + 1);}return 0; }

C.Palindromic Paths

思路

開(kāi)兩個(gè)數(shù)組,num1[i]num1[i]num1[i]記錄的是步數(shù)為iii的時(shí)候的位置上的111的個(gè)數(shù),num0[i]num0[i]num0[i]記錄的是步數(shù)為iii的時(shí)候的位置上000的個(gè)數(shù),因?yàn)檎w的步數(shù)就是在[1,n+m?1][1, n + m - 1][1,n+m?1]之間,所以我們可以通過(guò)對(duì)每一步全變?yōu)?span id="ozvdkddzhkzd" class="katex--inline">000或者全變?yōu)?span id="ozvdkddzhkzd" class="katex--inline">111中挑選一個(gè)最小值,作為我們的花費(fèi),然后累加花費(fèi)就是答案。

代碼

#include <bits/stdc++.h> #define mp make_pair #define pb push_backusing namespace std;typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull;const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }const int N = 2e5 + 10;int a[40][40];int num0[100], num1[100];int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {memset(num1, 0, sizeof num1);memset(num0, 0, sizeof num0);int n = read(), m = read();// cout << n << " " << m << endl;for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++) {a[i][j] = read();if(a[i][j] == 1) num1[i + j]++;else num0[i + j]++;}if(n == 2 && m == 2) {puts("0");// puts("");continue;}int ans = 0;int l = 2, r = n + m;while(l < r) {//好像這個(gè)if語(yǔ)句并沒(méi)有什么用,不知道比賽的時(shí)候怎么想的。if((num1[l] && num0[l]) || (num1[r] && num0[r]) || (num1[l] && num0[r]) || (num0[l] && num1[r]))ans += min(num0[l]+ num0[r], num1[l] + num1[r]);// cout << ans << "\n";l++, r--;}printf("%d\n", ans);// puts("");}return 0; }

D.Two Divisors

思路

先引入一個(gè)定理gcd(a,b)=1=gcd(a+b,a?b)gcd(a, b) = 1 = gcd(a + b, a * b)gcd(a,b)=1=gcd(a+b,a?b),所以這道題就簡(jiǎn)簡(jiǎn)單單就可以水過(guò)了,但是我的賽況卻不是如此,,,,,

那我們來(lái)證明一下這個(gè)定理的正確性吧:

假設(shè)有KaTeX parse error: Undefined control sequence: \and at position 15: gcd(x, y) = 1 \?a?n?d? ?gcd(x, z) = 1,所以gcd(x,y?z)=1gcd(x, y * z) = 1gcd(x,y?z)=1

gcd(a,b)=1?>gcd(a+b,b)=1=gcd(a,a+b)?>gcd(a+b,a?b)=1gcd(a, b) = 1 -> gcd(a + b, b) = 1 = gcd(a, a + b) - > gcd(a + b, a * b) = 1gcd(a,b)=1?>gcd(a+b,b)=1=gcd(a,a+b)?>gcd(a+b,a?b)=1

代碼

#include <bits/stdc++.h> #define mp make_pair #define pb push_backusing namespace std;typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull;const double eps = 1e-7; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }const int N1 = 1e7 + 10, N2 = 5e5 + 10;int prime[N1], cnt; int ans1[N2], ans2[N2], n; bool st[N1];int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);for(int i = 2; i < N1; i++) {if(!st[i]) prime[++cnt] = i;for(int j = 1; j <= cnt && i * prime[j] < N1; j++) {st[i * prime[j]] = true;if(i % prime[j] == 0) break;}}n = read();for(int i = 1; i <= n; i++) {int temp = read();ans1[i] = ans2[i] = -1;for(int j = 1; prime[j] * prime[j] <= temp; j++) {int x = 1;if(temp % prime[j] == 0) {while(temp % prime[j] == 0) {temp /= prime[j];x *= prime[j];}if(temp == 1) break;else {ans1[i] = x;ans2[i] = temp;break;}}}}for(int i = 1; i <= n; i++)printf("%d%c", ans1[i], i == n ? '\n' : ' ');for(int i = 1; i <= n; i++)printf("%d%c", ans2[i], i == n ? '\n' : ' ');return 0; }

總結(jié)

以上是生活随笔為你收集整理的Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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