比赛链接

A

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; bool solve() {
int n, m, k;
cin >> n >> m >> k;
int x, y;
cin >> x >> y;
bool ok = 1;
for (int i = 1;i <= k;i++) {
int xx, yy;
cin >> xx >> yy;
ok &= abs(x - xx) + abs(y - yy) & 1;
}
if (ok) cout << "YES" << '\n';
else cout << "NO" << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

B

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; vector<int> c[200007];
bool solve() {
int n, k;
cin >> n >> k;
for (int i = 1;i <= k;i++) c[i].clear();
for (int i = 1;i <= k;i++) c[i].push_back(0);
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
c[x].push_back(i);
}
for (int i = 1;i <= k;i++) c[i].push_back(n + 1); int ans = n;
for (int i = 1;i <= k;i++) {
priority_queue<int> pq;
for (int j = 1;j < c[i].size();j++) pq.push(c[i][j] - c[i][j - 1] - 1);
int mx = pq.top();
if (mx) {
pq.pop();
pq.push((mx - 1) / 2);
pq.push(mx / 2);
}
ans = min(ans, pq.top());
}
cout << ans << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

C

题意

给定长为 \(n\) 的数组 \(a,b\) ,每次操作使得 \(a_i,b_i = b_i,|a_i-b_i|(1\leq i \leq n)\) 。

问是否可以通过若干次操作使得 \(a_i = 0(1 \leq i \leq n)\) 。

题目

知识点:数论。

注意到,操作到最后一定能使得 \(a_i = 0\) ,并进入周期为 \(3\) 的循环,那么只要每个位置的数字进入循环的操作次数模 \(3\) 同余即可。

模拟操作显然是不行的。注意到 \(a_i \geq 2b_i\) 时,有 \((a_i,b_i) \to (b_i,a_i-b_i) \to (a_i-b_i,a_i-2b_i) \to (a_i-2b_i,b_i)\) 。因此,可以直接 \(a_i \bmod 2b_i\) ,这样不影响操作次数模 \(3\) 的结果。随后,执行操作一次继续上述操作。

时间复杂度 \(O(n \log 10^9)\)

空间复杂度 \(O(n)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; int a[100007], b[100007];
bool solve() {
int n;
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++) cin >> b[i]; int ok = -1;
for (int i = 1;i <= n;i++) {
if (a[i] == 0 && b[i] == 0) continue;
int tmp = 0;
while (a[i]) {
if (b[i]) a[i] %= 2 * b[i];
swap(a[i], b[i]);
b[i] = abs(a[i] - b[i]);
(++tmp) %= 3;
}
if (ok == -1) ok = tmp;
else if (ok != tmp) return false;
}
cout << "YES" << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << "NO" << '\n';
}
return 0;
}

D

题意

初始时有奖金 \(s\) ,接下来可以执行 \(k\) 次操作,每次操作以下的一种:

  1. 奖金 \(s\) 加上 \(s\) 的个位数字。
  2. 使用奖金 \(s\) ,不会使得奖金减少,使用的奖金会累加。

问最多能使用多少奖金。

题目

知识点:数学,三分。

显然要尽可能将 \(s\) 变大,再开始使用。

模拟操作1显然复杂度不行,考虑找到 \(s\) 增加的循环节。

我们发现 \(s \bmod 10 = 0 \text{ 或 } 5\) 时,至多操作 \(1\) 次就不需要继续操作了。因此,考虑取不操作的答案和操作 \(1\) 次的答案的最大值即可。

对于其他情况,至多操作 \(1\) 次就会进入 \(6,2,4,8\) 的循环,因此同样也记录不操作的答案和操作 \(1\) 次的答案的最大值,之后可以利用循环快速计算答案。

对于一开始的贪心结论,我们很容易想到凸函数三分求极值,但样例提示这不是一个凸函数。注意到,循环节长度只有 \(4\) ,若我们枚举终点在循环节中的位置,那么剩下的就是以常数 \(20\) 增加,这显然是个凸函数,可以用三分。

进一步地,最后那个凸函数是个二次函数,也可以直接求抛物线对称轴得到最值。

时间复杂度 \(O(\log k)\)

空间复杂度 \(O(1)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; bool solve() {
ll s, k;
cin >> s >> k;
ll ans = s * k;
s += s % 10;
k--;
ans = max(ans, s * k);
if (s % 10 == 0) {
cout << ans << '\n';
return true;
} auto check = [&](ll x) {
return (s + x * 20) * (k - x * 4);
};
for (int i = 0;i < 4 && k;i++, s += s % 10, k--) {
ll l = 0, r = k / 4;
while (l <= r) {
ll mid1 = l + (r - l) / 3;
ll mid2 = r - (r - l) / 3;
if (check(mid1) <= check(mid2)) l = mid1 + 1;
else r = mid2 - 1;
}
ans = max(ans, check(r));
}
cout << ans << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

Codeforces Round #885 (Div. 2) A-D的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. OI 数论中的上界估计与时间复杂度证明

    预备 0.1 渐进符号 其实不少高等数学 / 数学分析教材在讲解无穷小的比较时已经相当严谨地介绍过大 O.小 O 记号,然而各种历史习惯记法的符号滥用(abuse of notation)[1] 直到 ...

  2. C++冒泡排序简单讲解

    此文章我已在洛谷博客发布,不算抄袭 什么是冒泡排序 冒泡排序(Bubble Sort)也是一种简单直观的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访 ...

  3. DevOps、SRE、平台工程的区别

    DevOps.SRE和平台工程的概念在不同时期出现,并由不同的个人和组织开发. DevOps作为一个概念是由Patrick Debois和Andrew Shafer在2009年的敏捷会议上提出的.他们 ...

  4. 【机器学习与深度学习理论要点】11.什么是L1、L2正则化?

    机器学习中几乎都可以看到损失函数后面会添加一个额外项,常用的额外项一般有两种,一般英文称作 L1-norm 和L2-norm,中文称作 L1正则化 和 L2正则化,或者 L1范数 和 L2范数.L1正 ...

  5. Linux 内存管理 pt.2

    哈喽大家好我是咸鱼,在<Linux 内存管理 pt.1>中我们学习了什么是物理内存.虚拟内存,了解了内存映射.缺页异常等内容 那么今天我们来接着学习 Linux 内存管理中的多级页表和大页 ...

  6. Prism Sample 11-UsingDelegateCommands

    本例的知识点,全在ViewModel中,看代码: 1 public class MainWindowViewModel : BindableBase 2 { 3 private bool _isEna ...

  7. vscode取消“禁用错误波形曲线”

    刚刚不小心点到了vscode的禁用错误波形曲线,导致现在没有报错提醒了,上网查了一下,重新打开错误曲线的方法是 1.按住Cctrl+shift+p 2.搜索 启用错误波形曲线,选择打开,就可以了

  8. 2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。

    2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和. n比较大,10的5次方. 来自美团.3.26笔试. 答案2022-06-23: 要i还是不要i,递归. ...

  9. nodejs 入门基本概念

    nodejs 的诞生   Node.js 是2009的时候由大神 Ryan Dahl 开发的.Ryan 的本职工作是用 C++ 写服务器,后来他总结出一个经验,一个高性能服务器应该是满足"事 ...

  10. Github Copilot Chat 初体验

    最近因为阳了的缘故一直躺在床上.今天终于从床上爬起来了.不是因为好透了,而是因为我收到了申请Copilot Chat preview 权限通过的邮件.实在忍不住,于是起床开电脑在咳嗽声中进行了一番体验 ...