Codeforces Round 909 (Div. 3)

1|0基本情况

  • 第一次在 CFAC 了超过一道题。(毕竟是Div3
  • B 题卡住了很久。
  • D 没有深入思考。

2|0B. 250 Thousand Tons of TNT

Problem - B - Codeforces

一开始死活过不了的代码:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define ll long long using namespace std; const int N = 150000 + 10; long long s[N]; long long a[N]; long long ans = 0; int n, t; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> t; while (t--) { cin >> n; ans = 0; long long maxx = 0, minn = 0x7fffffff; for (int i = 1; i <= n; i++) { cin >> a[i]; maxx = max(a[i], maxx); minn = min(a[i], minn); } if (n == 1) { cout << 0 << endl; continue; } ans = max(ans, maxx - minn); for (int t = 2; t < n; t++) { if (n % t == 0) { maxx = 0, minn = 0x7fffffff; for (int i = t; i <= n; i += t) { ll temp = 0; for (int k = i - t + 1; k <= i; k++) { temp += a[k]; } maxx = max(maxx, temp); minn = min(minn, temp); } ans = max(ans, maxx - minn); } } cout << ans << endl; } return 0; }

已经觉察到可能爆int 而改了 long long

但一是因为基础不扎实,二是不会造数据

导致我搞了快一个小时都没有发现问题所在:

minn = 0x7fffffff

我初始化的极大值只是int下的极大值,导致了数据范围超过 int 后就会出现正确性问题。

改成 minn = 0x7fffffffffffffff即可。

但凡我能直接意识到这个问题,或者手造数据时候能造大一点都能 hack 掉自己的代码。

3|0D. Yarik and Musical Notes

Problem - D - Codeforces

这题我已经推到 2ab=ab,然而没有继续推导下去,而是尝试用不严谨的写法来做。

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 2e5 + 10; int a[N]; bool check(int n, int m) { if (n == m) return true; if ((m / n) % 2) return false; return ((m / n) == (1 << (m - n))); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t, n; cin >> t; while (t--) { long long ans = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = n; i >= 1; i--) { for (int j = i - 1; j >= 1; j--) { if (check(a[j], a[i])) { ans++; } } } cout << ans << endl; } return 0; }

显然,1 << (m - n)会爆范围。。。

看了题解,发现继续推下去就轻松了。

suppose that b=a2k(k>0)

aa2k=2a2a2k12k=12(2k1)a2k=2(2k1)a

  • k=1
    • a=1,b=2
  • k>1
    • 2k1>k
    • can't be satisfied

Thus, the only possible cases where the equality is satisfied are if bi=bj or bi=1,bj=2,(and vice versa). The number of such pairs can be counted for O(nlogn)

代码

#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; vector<int> a(n); for (int& x : a) cin >> x; ll ans = 0; map<int, int> cnt; for (int i = 0; i < n; i++) { ans += cnt[a[i]]; if (a[i] == 1) ans += cnt[2]; else if (a[i] == 2) ans += cnt[1]; cnt[a[i]]++; } cout << ans << "\n"; } signed main() { int t; cin >> t; while (t--) solve(); }

__EOF__

本文作者Kdlyh
本文链接https://www.cnblogs.com/kdlyh/p/17842675.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   加固文明幻景  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示