Educational Codeforces Round 143

1|0A. Two Towers


#include <bits/stdc++.h> using namespace std; #define int long long #define mp make_pair using pii = pair<int, int>; using vi = vector<int>; constexpr int inf = 1e18; void solve(){ int n , m , cnt = 0; string a , b; cin >> n >> m; cin >> a >> b; reverse(b.begin(), b.end()); a += b; for( int i = 1 ; i < a.size() ; i ++ ) cnt += (a[i] == a[i-1]); cout << ( cnt <= 1 ? "YES\n" : "NO\n"); } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; for( cin >> t ; t ; t -- ) solve(); return 0; }

2|0B. Ideal Point


找一下是否存在两个区间的交集只包含k

#include <bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; using vi = vector<int>; #define mp make_pair constexpr int inf = 1e18; void solve() { int n , k; cin >> n >> k; vector<pii> e(n); for( auto & [l , r ] : e ) cin >> l >> r; for( const auto & [ a , b ] : e ) for( const auto & [ c , d ] : e ){ int l = max(a , c ) , r = min( b , d ); if( l == r and l == k ){ cout << "YES\n"; return ; } } cout << "NO\n"; return; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; for (cin >> t; t; t--) solve(); return 0; }

3|0C. Tea Tasting


对于每一种茶来说,二分的求出能够品尝他的人的区间,然后对这部分人进行区间修改,然后对于边界单独处理一下即可。

#include <bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; using vi = vector<int>; #define mp make_pair constexpr int inf = 1e18; void solve() { int n; cin >> n; vi a(n + 1), b(n + 1), c(n + 2), d(n + 2); for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; for (int i = 1; i <= n; i++) { int l = i, r = n, ans = i - 1; for (int mid, t; l <= r;) { mid = (l + r) / 2, t = a[mid] - a[i - 1]; if (t <= b[i]) ans = mid, l = mid + 1; else r = mid - 1; } if (ans >= i) c[i]++, c[ans + 1]--; d[ans + 1] += b[i] - a[ans] + a[i - 1]; } for (int i = 1; i <= n; i++) { c[i] += c[i-1]; cout << c[i] * (a[i] - a[i-1] ) + d[i] << " "; } cout << "\n"; return; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; for (cin >> t; t; t--) solve(); return 0; }

4|0D. Triangle Coloring


简单带说就是要给边权最大的两条边染上不同颜色,考虑最大值是否相同,可以计算出染色方案数。

然后就是考虑第三个的点的染色方案,因为要保证红蓝数量相同,所以要从环里面选出一半来。

#include <bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; using vi = vector<int>; #define mp make_pair constexpr int inf = 1e18; constexpr int mod = 998244353; const int N = 3e5 + 5; int fact[N], invFact[N]; int power(int x, int y) { int ans = 1; while (y) { if (y & 1) ans = ans * x % mod; x = x * x % mod, y >>= 1; } return ans; } int inv(int x) { return power(x, mod - 2); } int C(int x, int y) { return fact[x] * invFact[x - y] % mod * invFact[y] % mod; } void solve() { int n; cin >> n, n /= 3; vector<array<int, 3>> e(n); for (auto &it: e) for (auto &i: it) cin >> i; int res = 1; for (auto &it: e) { sort(it.begin(), it.end()); if (it[0] == it[1] and it[1] == it[2]) res = res * 3 % mod; else if (it[0] == it[1]) res = res * 2 % mod; } res = res * C(n, n / 2) % mod; cout << res << "\n"; return; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); fact[0] = 1, invFact[0] = inv(1); for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % mod, invFact[i] = inv(fact[i]); solve(); return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17714859.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
历史上的今天:
2022-09-19 数据结构实验(三)线性表的操作与应用
2022-09-19 2022 Jiangsu Collegiate Programming Contest
点击右上角即可分享
微信分享提示