当前位置:网站首页>Codeforces Round #804 (Div. 2)(5/5)
Codeforces Round #804 (Div. 2)(5/5)
2022-07-27 07:14:00 【eyuhaobanga】
structure + guess
AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; void Solve() { int n; cin >> n; if (n & 1) { cout << "-1\n"; } else { cout << "0 0 " << n / 2 << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep(i, 0, T) { Solve(); } return 0; }structure + Looking for a regular
AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; void Solve() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int> (m)); rep (i, 0, n) { rep (j, 0, m) { if ((i % 4 == 0 && (j % 4 == 0 || j % 4 == 3)) || ((i % 4 == 1 || i % 4 == 2) && (j % 4 == 1 || j % 4 == 2)) || (i % 4 == 3 && (j % 4 == 0 || j % 4 == 3))) { cout << "1 "; } else { cout << "0 "; } } cout << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep(i, 0, T) { Solve(); } return 0; }mex Mathematical induction
AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; using i64 = long long; const int P = 1e9 + 7; // assume -P <= x < 2P int norm(int x) { if (x < 0) { x += P; } if (x >= P) { x -= P; } return x; } template<class T> T power(T a, i64 b) { T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; } struct Z { int x; Z(int x = 0) : x(norm(x)) {} Z(i64 x) : x(norm(x % P)) {} int val() const { return x; } Z operator-() const { return Z(norm(P - x)); } Z inv() const { assert(x != 0); return power(*this, P - 2); } Z &operator*=(const Z &rhs) { x = i64(x) * rhs.x % P; return *this; } Z &operator+=(const Z &rhs) { x = norm(x + rhs.x); return *this; } Z &operator-=(const Z &rhs) { x = norm(x - rhs.x); return *this; } Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); } friend Z operator*(const Z &lhs, const Z &rhs) { Z res = lhs; res *= rhs; return res; } friend Z operator+(const Z &lhs, const Z &rhs) { Z res = lhs; res += rhs; return res; } friend Z operator-(const Z &lhs, const Z &rhs) { Z res = lhs; res -= rhs; return res; } friend Z operator/(const Z &lhs, const Z &rhs) { Z res = lhs; res /= rhs; return res; } friend std::istream &operator>>(std::istream &is, Z &a) { i64 v; is >> v; a = Z(v); return is; } friend std::ostream &operator<<(std::ostream &os, const Z &a) { return os << a.val(); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> a(n + 1), p(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]++; p[a[i]] = i; } int l = p[1], r = p[1]; Z ans = 1; for (int i = 2; i <= n; i++) { if (p[i] < l) { l = p[i]; } else if (p[i] > r) { r = p[i]; } else { ans *= (r - l - i + 2); } } cout << ans << '\n'; } return 0; }dp
AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<int> a(n + 1), dp(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { vector<int> cnt(n + 1); dp[i] = -0x3f3f3f3f; int maxx = 0; for (int j = i - 1; j >= 0; j--) {//j+1.....i-1(i-1-j-1+1)->i-j-1 if ((i - j - 1) % 2 == 0 && maxx <= (i - j - 1) / 2 && (j == 0 || a[i] == a[j])) { dp[i] = max(dp[i], dp[j] + 1); } cnt[a[j]]++; maxx = max(maxx, cnt[a[j]]); } } int ans = 0; int maxx = 0; vector<int> cnt(n + 1); for (int i = n; i >= 0; i--) { if ((n - i) % 2 == 0 && maxx <= (n - i) / 2) { ans = max(ans, dp[i]); } cnt[a[i]]++; maxx = max(maxx, cnt[a[i]]); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep (i, 0, T) { Solve(); } return 0; }dp+two pointers
AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; void Solve() { int n, m; cin >> n >> m; vector<int> dp(m + 1); vector<int> cnt(m + 1); vector<bool> vis(m + 1); for (int i = 1; i <= m; i++) { dp[i] = i; } int l = 1e9 + 7, r = -1e9; rep(i, 0, n) { int x; cin >> x; cnt[x] = 1; vis[x] = true; l = min(x, l); r = max(x, r); } int ans = r - l; for (int i = sqrt(m) + 1; i > 0; i--) { for (int j = i; j <= m; j += i) { if (vis[j]) { cnt[dp[j]]--; } if (dp[j / i] >= i) { dp[j] = min(dp[j], dp[j / i]); } if (vis[j]) { cnt[dp[j]]++; } } while (cnt[r] == 0) { r--; } ans = min(ans, r - min(l, i)); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep (i, 0, T) { Solve(); } return 0; }
边栏推荐
- Working principle analysis of deepsort
- Bert and RESNET can also be trained on mobile phones?!
- Digital image processing - Chapter 6 color image processing
- Shell programming specifications and variables
- Watermelon book learning notes - Chapter 4 decision tree
- Codeforces Round #787 (Div. 3)(7/7)
- (转帖)eureka、consul、nacos的对比1
- Day012 application of one-dimensional array
- MySQL query operation index optimization practice
- What is OKR and what is the difference between OKR and KPI
猜你喜欢

Using docker to install and deploy redis on CentOS

Netease Yunxin appeared at the giac global Internet architecture conference to decrypt the practice of the new generation of audio and video architecture in the meta universe scene

肽核酸PNA-多肽PNA-TPP|Glt-Ala-Ala-Pro-Leu-pNA|Suc-Ala-Pro-pNA|Suc-AAPL-pNA|Suc-AAPM-pNA

newest! SASAC releases new measures for digital transformation of state-owned enterprises

齐岳:巯基修饰寡聚DNA|DNA修饰CdTe/CdS核壳量子点|DNA偶联砷化铟InAs量子点InAs-DNA QDs

Qi Yue: thiol modified oligodna | DNA modified cdte/cds core-shell quantum dots | DNA coupled indium arsenide InAs quantum dots InAs DNA QDs

如何借助自动化工具落地DevOps|含低代码与DevOps应用实践

Watermelon book chapter 3 - linear model learning notes

(转帖)eureka、consul、nacos的对比2

Web configuration software for industrial control is more efficient than configuration software
随机推荐
“蔚来杯“2022牛客暑期多校训练营1
DNA modified noble metal nanoparticles | DNA modified gold nanoparticles (scientific research level)
Codeforces Round #809 (Div. 2)(6/6)(Kruskal重构树)
运行代码报错: libboost_filesystem.so.1.58.0: cannot open shared object file: No such file or directory
Dimension problems and contour lines
Interpretation of deepsort source code (VII)
ZnS DNA QDs near infrared zinc sulfide ZnS quantum dots modified deoxyribonucleic acid dna|dna modified ZnS quantum dots
pre-commit install 时 CalledProcessError
DNA修饰贵金属纳米颗粒|脱氧核糖核酸DNA修饰纳米金(科研级)
用typescript实现排序-递增
PNA modified polypeptide arms PNA PNA DNA suc aapf PNA suc - (ALA) 3 PNA
基于SSM医院预约管理系统
The issuing process of individual developers applying for code signing certificates
DNA偶联PbSe量子点|近红外硒化铅PbSe量子点修饰脱氧核糖核酸DNA|PbSe-DNA QDs
Codeforces Round #787 (Div. 3)(7/7)
DNA modified near infrared two region GaAs quantum dots | GaAs DNA QDs | DNA modified GaAs quantum dots
OpenGL development with QT (I) drawing plane graphics
Cyclegan parsing
Significance of NVIDIA SMI parameters
DNA(脱氧核糖核酸)供应|碳纳米管载核酸-DNA/RNA材料|DNA/RNA核酸修饰磁性纳米颗粒