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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces 1323 div2题解ABC

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

A. Even Subset Sum Problem
簽到題

#include <bits/stdc++.h> using namespace std; template <typename t> void read(t &x) {char ch = getchar();x = 0;t f = 1;while (ch < '0' || ch > '9')f = (ch == '-' ? -1 : f), ch = getchar();while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();x *= f; }#define wi(n) printf("%d ", n) #define wl(n) printf("%lld ", n) #define P puts(" ") typedef long long ll; #define MOD 1000000007 #define mp(a, b) make_pair(a, b) #define N 20005 #define rep(i, j, n) for (int i = j; i <= n; i++) #define red(i, n, j) for (int i = n; i >= j; i--) #define fil(a, n) rep(i, 0, n, ) read(a[i])//---------------https://lunatic.blog.csdn.net/-------------------//vector<int> a[2]; int main() {int t, n, x;read(t);while (t--){a[0].clear();a[1].clear();read(n);rep(i, 1, n + 1){read(x);x %= 2;a[x].push_back(i);}if (!a[0].empty()){puts("1");wi(a[0][0]),P;}else if (a[1].size() > 1)puts("2");wi(a[1][0]),wi(a[1][1] ),P;elseputs("-1");}return 0; }

B. Count Subrectangles
當(dāng)時沒做出來:
預(yù)處理:
首先統(tǒng)計 a序列和 b序列 的所有連續(xù) 1 區(qū)間長度, a 序列第 i 個連續(xù) 1 的區(qū)間length 為Ai ,b 序列第 i 個連續(xù) 1 的區(qū)間length 為Bi
考慮 k 的每一個約數(shù) d。
則有, d×kd 這個矩形的個數(shù)就是 (Ai?d+1) *(Bi?kd+1) ,對k的每一個因子d計算后求和即可。
解答:
然后排序后二分輸出。

#include <bits/stdc++.h> using namespace std; template <typename t> void read(t &x) {char ch = getchar();x = 0;t f = 1;while (ch < '0' || ch > '9')f = (ch == '-' ? -1 : f), ch = getchar();while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();x *= f; }#define wi(n) printf("%d ", n) #define wl(n) printf("%lld ", n) #define P puts(" ") typedef long long ll; #define MOD 1000000007 #define mp(a, b) make_pair(a, b) #define N 20005 #define rep(i, j, n) for (int i = j; i <= n; i++) #define red(i, n, j) for (int i = n; i >= j; i--) #define fil(a, n) rep(i, 0, n, ) read(a[i])//---------------https://lunatic.blog.csdn.net/-------------------//const int N = 4e4 + 100; int a[N], b[N]; vector<pair<int, int>> node; void init(int k) {for (int i = 1; i * i <= k; i++){if (k % i == 0){node.push_back(make_pair(i, k / i));if (i != k / i)node.push_back(make_pair(k / i, i));}} } unordered_map<int, int> A, B; void solve(int a[], int n, unordered_map<int, int> &mp) {int pos = 1, cnt = 0;while (pos <= n){while (a[pos]){pos++;cnt++;}if (cnt){mp[cnt]++;cnt = 0;}pos++;} }int main() {int n, m, k;read(n), read(m), read(k);init(k);rep(i, 1, n + 1)read(a[i]);rep(i, 1, m + 1)read(b[i]);solve(a, n, A);solve(b, m, B);LL ans = 0;rep(k, 0, node.size()){int x = node[k].first, y = node[k].second;LL xx = 0, yy = 0;for (auto it : A)if (it.first >= x)xx += it.second * (it.first - x + 1);for (auto it : B)if (it.first >= y)yy += it.second * (it.first - y + 1);ans += xx * yy;}wi(ans), P;return 0; }

C. Unusual Competitions
我覺得這個題應(yīng)該和B換一換
這個題把左括號看成-1,右括號看成1,如果前綴和小于0即存在單獨(dú)的右括號,需要重排。
然后找到所有前綴和為負(fù)的連續(xù)段包括最后一個0,計算長度和就行。

#include <bits/stdc++.h> using namespace std; template <typename t> void read(t &x) {char ch = getchar();x = 0;t f = 1;while (ch < '0' || ch > '9')f = (ch == '-' ? -1 : f), ch = getchar();while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();x *= f; }#define wi(n) printf("%d ", n) #define wl(n) printf("%lld ", n) #define P puts(" ") typedef long long ll; #define MOD 1000000007 #define mp(a, b) make_pair(a, b) #define N 20000005 #define rep(i, j, n) for (int i = j; i <= n; i++) #define red(i, n, j) for (int i = n; i >= j; i--) #define fil(a, n) rep(i, 0, n, ) read(a[i])//---------------https://lunatic.blog.csdn.net/-------------------//string s; int a[N], n, ans = 0; int main() {read(n);cin >> s;rep(i, 0, n){a[i] = a[i - 1] + (s[i] == '(' ? -1 : 1);}if (a[n - 1] != 0)puts("-1");else{rep(i, 0, n) ans += (a[i] < 0) + (a[i] < 0 && a[i - 1] >= 0);wi(ans),P;}return 0; }

總結(jié)

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

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