Educational Codeforces Round 104

https://codeforces.com/contest/1487

1|0A. Arena


统计与最小值不同的数字数量。

#include <bits/stdc++.h> using namespace std; #define int long long const int M = (1 << 15) - 1; void solve(){ int n; cin >> n; vector<int> a(n); for( auto &i : a ) cin >> i; sort(a.begin(), a.end()); for( auto i : a ){ if( i != a[0] ) break; n --; } cout << n << "\n"; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while( t -- ) solve(); return 0; }

2|0B. Cat Cycle


首先如果n是偶数,则A,B不会相遇。当n是奇数是,B每一圈都多走了 1 步,这里的一圈是指圈上所有的点被覆盖过一次,并且每n2步可以完整的覆盖一次。所以计算完整覆盖了多少次即可。

#include <bits/stdc++.h> using namespace std; #define int long long const int M = (1 << 15) - 1; void solve() { int n, k, f; cin >> n >> k, k -- , f = n / 2; cout << (k + (n % 2) * (k / f)) % n + 1 << "\n"; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while (t--) solve(); return 0; }

3|0C. Minimum Ties


首先,当n为奇数的时候,每只球队需要参与偶数场比赛,所以不用平局,反之每只球队至少产生一次平局。

我们保证球队ij2(ji)<n即可。

当然本题构造方法有很多种。

#include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int n; cin >> n; for( int i = 1 ; i <= n ; i ++ ) for( int j = i+1 ; j <= n ; j ++ ){ if( 2*(j-i) == n ) cout << "0 "; else if( 2*(j-i) < n ) cout <<"1 "; else cout << "-1 "; } cout << "\n"; return ; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while( t -- ) solve(); return 0; }

4|0D. Pythagorean Triples


我们要找同时满足1abcn,a2+b2=c2,a2b=c

(a,b,c)的数量,首先把两个等式作差可以得到b2+b=c2cb(b+1)=c(c1),所以c=b+1

带回原式可得a2=2b+1因为bn所以a2=2b+12n+1。这样我们O(n)的求出所有符合条件的a即可,当然也可以用数学方法O(1)的解出答案。

另外一点要注意的是a2=2b+1,所以a一定是奇数。

#include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int n , res = 0; cin >> n; for( int i = 3 , N = 2*n-1; i * i <= N ; i += 2 ) res ++; cout << res << "\n"; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while( t -- ) solve(); return 0; }

5|0E. Cheap Dinner


f[i][j]表示第i种菜,选择j的最小代价,则转移方程就是f[i][j]=minf[i1][k]+a[i][j],(k,j){(xi1,yi1)},这样的话实际上转换成了一个带修改的 RMQ问题,并且每次询问的区间都是完整的区间,当然我们可以使用各种数据结构来解决这个问题。

这里我们 multiset 来维护f[i1][k]的最小值,每次枚举点后,把所有不能转移过来的点删掉,计算答案后再重新加回去,复杂度O(mlogn)

#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); vector<int> n(4); for (auto &i: n) cin >> i; vector<vector<int>> a(4); for (int i = 0; i < 4; i++) { a[i] = vector<int>(n[i]); for (auto &j: a[i]) cin >> j; } for (int i = 1, m; i < 4; i++) { cin >> m; vector<vector<int>> e(n[i] + 1); for (int x, y; m; m--) cin >> x >> y, x--, y--, e[y].push_back(x); multiset<int> cnt; for (auto j: a[i - 1]) cnt.insert(j); for (int j = 0; j < n[i]; j++) { for (auto k: e[j]) cnt.erase(cnt.lower_bound(a[i - 1][k])); if (cnt.empty()) a[i][j] = inf; else a[i][j] += *cnt.begin(); for (auto k: e[j]) cnt.insert(a[i - 1][k]); } } int res = *min_element(a[3].begin(), a[3].end()); if( res >= inf ) res = -1; cout << res; return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17601349.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示