比赛链接:Here

1562A. The Miracle and the Sleeper

题意:

  • 给出 \(l,r\) 求出最大化的 \(a\ mod\ b\) (\(l\le b\le b\le a\le r\))

思路:

很容易就看出 \(l\le ⌊\frac r2⌋ + 1\) 时 \(r\bmod \left(\left\lfloor\frac{r}{2}\right\rfloor+1\right)=\left\lfloor\frac{r-1}{2}\right\rfloor\)​​ 就是最大可能的答案,

但如果 \(l > ⌊\frac r2⌋ + 1\) 的话最大值应该是 \(r\bmod l=r - l\)

时间复杂度:\(\mathcal{O}(1)\)

void solve() {
ll l, r;
cin >> l >> r;
if (r / 2 >= l) cout << ((r - 1) / 2) << "\n";
else cout << r % l << "\n";
}

1562B. Scenes From a Memory

题意:

  • 给出一个字符串 \(s\; (|s|\le50)\) 请问可以从字符串中删除的最大位数是多少使得字符串数字变为非素数? 如:\(237\) 删除第二位的 \(3\) 变为 \(27\)

思路:

说实话赛时想复杂了,因为在 \(|s|\le 50\)​ 的情况下其实素数并不多(实际也只要考虑 \(3\)​ 位数的情况就ok),即使直接去模拟情况都可以。

但利用素数筛就能很快AC了

bool prime[110];
int n;
string s;
void solve() {
for (int i = 0; i < n; i++) {
if (s[i] == '1' || s[i] == '4' || s[i] == '6' || s[i] == '8' || s[i] == '9') {
cout << 1 << endl;
cout << s[i] << endl;
return;
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (!prime[(s[i] - '0') * 10 + (s[j] - '0')]) {
cout << 2 << endl;
cout << s[i] << s[j] << endl;
return;
}
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
for (int i = 2; i < 100; ++i) {
prime[i] = 1;
for (int j = 2; j * j <= i; ++j)
if (i % j == 0)prime[i] = 0;
}
int _; for (cin >> _; _--;) {
cin >> n >> s;
solve();
}
}

1562C. Rings

题意:

  • 给出一个 \(01\) 字符串,以及函数 \(f(s):\) 将 $01 $ 转为十进制整数,请找出两对下标 \((l_1,r_1),(l_2,r_2)\) 使得 \(f(s_{(l_1,r_1)}) = k\times f(s_{(l_2,r_2)})\) 成立

思路:

麻了,前面应是没想到怎么去构造一个这样的等式,手写 \(11,..,1\) 和 \(00,...,0\) 等特殊情况的时候想到我只要定位到第一个 \(0(pos)\) 的位置就可以了,然后以 \(pos\) 为界划分为两部分就肯定能构造 \(f(s_{(l_1,r_1)}) = k\times f(s_{(l_2,r_2)})\)

const int N = 1e5 + 10;
int main() {
// ! 记得注释掉,麻了,输入流乱了导致后面debug半天没找到问题
// cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n; cin >> n;
char s[N];
scanf("%s", s + 1);
ll cnt0 = 0, cnt1 = 0;
for (int i = 1; i <= n; ++i) if (s[i] == '1') cnt1 += 1;
if (cnt1 == n) {
cout << "1 " << n - 1 << " 2 " << n << "\n";
continue;
}
int p = 0;
for (int i = 1; i <= n; ++i)
if (s[i] == '0') {
p = i;
break;
}
if (p - 1 < (n / 2)) cout << p << " " << n << " " << p + 1 << " " << n << "\n";
else cout << 1 << " " << p << " " << 1 << " " << p - 1 << "\n";
}
}

1562D. Two Hundred Twenty One (Easy and Hard)

题意:

题意待补

思路:

把 \(+,-\) 号转为 \(+1,-1\) 再维护前缀和,可以快速判断奇偶(D1)

核心在于利用前缀和进行二分(D2)

不过有人用 map + set 也过了就很神奇(TQL

// D1
const int N = 3e5 + 10;
int a[N], sum[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, q;
string s;
cin >> n >> q >> s;
int id = 0;
for (int i = 0; i < s.size(); ++i) {
if (i & 1) {
if (s[i] == '+') a[++id] = -1;
else a[++id] = 1;
} else {
if (s[i] == '-') a[++id] = -1;
else a[++id] = 1;
}
sum[id] = sum[id - 1] + a[id];
}
while (q--) {
int l, r; cin >> l >> r;
if (abs(sum[r] - sum[l - 1]) == 0) cout << "0\n";
else if (abs(sum[r] - sum[l - 1]) & 1) cout << "1\n";
else cout << "2\n";
}
}
}
// D2
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, q;
cin >> n >> q;
string _s;
cin >> _s;
vector<int> which(n);
for (int i = 0; i < n; i++) {
which[i] = (_s[i] == '-') != (i & 1);
}
vector<int> psum(n + 1, 0);
for (int i = 0; i < n; i++) {
psum[i + 1] = psum[i] + (which[i] ? -1 : 1);
}
while (q--) {
int l, r;
cin >> l >> r; l--; r--;
if (psum[r + 1] == psum[l]) cout << "0\n\n";
else {
if ((r + 1 - l) & 1) cout << "1\n";
else {
cout << "2\n";
cout << (r + 1) << ' ';
r--;
}
int d = min(psum[l], psum[r + 1]) + abs(psum[l] - psum[r + 1]) / 2;
// d -> d+1
int s = l;
int e = r + 1;
while (s + 1 < e) {
int m = (s + e) / 2;
if ((psum[m] <= d) == (psum[s] <= d)) s = m;
else e = m;
}
cout << s + 1 << "\n";
}
}
}
}

Codeforces Round #741 (Div. 2) 个人题解 A~D的更多相关文章

  1. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  2. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  3. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  4. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  5. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  6. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  7. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  8. Codeforces Round #545 (Div. 1) 简要题解

    这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...

  9. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  10. Codeforces Round #821(Div.2) (A-C) 题解

    Codeforces Round #821(Div.2) (A-C) A.Consecutive Sum 大致题意 给定一组共 n 个数据 ,如果俩个数的下标在 mod k 意义下同余,则可以交换a[ ...

随机推荐

  1. java把数据批量插入iotdb

    package com.xlkh.kafka; import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson ...

  2. Jenkins中HTML报告无法正常显示问题解决

    自动化结果生成了HTML报告,但是在Jenkins中打开报告却显示空白,打开控制台,可以看到该报错 参考https://www.jenkins.io/doc/book/security/configu ...

  3. 记一次 .NET 某零售管理系统 存储不足分析

    一:背景 1. 讲故事 前几天有位朋友找到我,说他的程序会偶发性的报 存储空间不足,无法处理此命令 的错误,让我帮忙看下到底怎么回事,哈哈,人家是有备而来,dump都准备好了,话不多说,直接分析开干. ...

  4. 本地数据备份与FTP远程数据迁移

    数据是电脑中最重要的东西.为了保证数据安全,我们经常会对数据进行备份.之前一直采用将重要数据拷贝至移动硬盘的方式实现备份,实现简单但每次都需要把所有文件拷贝一次,当文件很大时效率较低. 因此,考虑使用 ...

  5. 将mysql的输出文本写回mysql

    1 准备工作 1.1 环境准备 操作系统:Microsoft Windows 10 专业工作站版 软件版本:Python 3.9.6 第三方包: pip install pandas2.1.0 pip ...

  6. vue-test --------事件修饰符

    <template> <h3>事件修饰符</h3> <a @click="clickHandle" href="www.baid ...

  7. 华企盾DSC手机app登录不上常见处理方法

    1.DSC服务器是否正常运行. 2.telnet外网是否通.(需要在程序与功能中添加telnet功能才能在cmd窗口用telnet命令 举例:telnet 172.17.2.20 5558) 3.其它 ...

  8. 一键打包,随时运行,Python3项目虚拟环境一键整合包的制作(Venv)

    之前我们介绍了如何使用嵌入式 Python3 环境给项目制作一键整合包,在使用嵌入式 Python 环境时,通常是作为另一个应用程序的一部分,而Python3虚拟环境是为了在开发过程中隔离项目所需的 ...

  9. ASR项目实战-交付过程中遇到的疑似内存泄漏问题

    基于Kaldi实现语音识别时,需要引入一款名为OpenFST的开源软件,本文中提到的内存问题,即和这款软件相关. 考虑到过程比较曲折,内容相对比较长,因此先说结论. 在做长时间的语音识别时,集成了Ka ...

  10. Kubernetes架构及安装

    K8s架构 k8s内部是有几个组件的,分别是controller manager,api-server,scheduler,kubelet以及etcd,kube-proxy还有k8s客户端kubect ...