当前位置: 首页 > news >正文

Codeforces Round 932(div2)||ABD

A-Entertainment in MAC

题意

可以对一个字符串进行两种操作:

  1. 将字符串反转
  2. 将该字符串反转后接在原串的后面。

可以进行任意次上述操作,获得字典序最小的字符串。

数据范围

t ( 1 ≤ t ≤ 500 ) t(1≤t≤500) t(1t500)

n ( 2 ≤ n ≤ 1 0 9 ) n(2≤n≤10^9) n(2n109)

s ( 1 ≤ ∣ s ∣ ≤ 100 ) s(1\le |s|\le 100) s(1s100)

思路

对比反转前后的字符串字典序大小,再决定是操作1还是操作2

参考代码

void solve() {ll n;cin >> n;string s;cin >> s;string t = s;reverse(t.begin(), t.end());if (s > t) {cout << t << s << endl;}else {cout << s << endl;}
}

B-Informatics in MAC

题意

M E X MEX MEX:不属于该数组的最小非负整数。

对一个数组分成 k k k个子段,要求每段的 M E X MEX MEX都等于相同的数。

找到这样的子段分法,或者报告不存在合法的分法。

数据范围

t ( 1 ≤ t ≤ 1 0 4 ) t(1≤t≤10^4) t(1t104)

n ( 2 ≤ n ≤ 1 0 5 ) n(2≤n≤10^5) n(2n105)

a i ( 0 ≤ a i < n ) a_i(0\le a_i\lt n) ai(0ai<n)

思路

假设 M E X = 2 MEX=2 MEX=2,则分成 k k k段的方式为前 k − 1 k-1 k1段只要都出现过 0 , 1 0,1 0,1就进行分段,最后一段保证含 0 , 1 0,1 0,1和达到第 n n n个数。

确定 M E X MEX MEX:遍历数组 a a a,找到最小的没有出现过的数(该数不大于 n n n),该数即为 M E X MEX MEX

参考代码

// MEX:不属于该数组的最小非负整数void solve() {ll n;cin >> n;vector<ll>a(n + 1);vector<bool>ck(n + 1, false);for (int i = 1;i <= n;i++) {ll x;cin >> x;a[i] = x;ck[x] = true;}bool f = false;int y = -1;for (int i = 0;i < n;i++) {if (ck[i] == false) {y = i;f = true;break;}}if (!f) {cout << -1 << endl;return;}// MEX=y// cout << y << endl;if (y == 0) {cout << n << endl;for (int i = 1;i <= n;i++) {cout << i << ' ' << i << endl;}return;}int p = 1;int cnt = 0;vector<pair<int, int>>ans;vector<bool>hs(y, false);vector<bool>hsf(y, false);for (int i = 1;i <= n;i++) {if (a[i] < y && !hs[a[i]]) {hs[a[i]] = true;cnt++;}if (cnt == y) {ans.push_back({ p, i });p = i + 1;cnt = 0;// 会不会Tlehs = hsf;}}if (ans.size() == 1) {cout << -1 << endl;return;}cout << ans.size() << endl;for (int i = 0;i < ans.size();i++) {if (i != ans.size() - 1)cout << ans[i].first << " " << ans[i].second << endl;else {cout << ans[i].first << " " << n << endl;}}}

D-Exam in MAC

题意

有一个集合 s s s

找到满足 0 ≤ x ≤ y ≤ c 0\le x\le y\le c 0xyc x + y x+y x+y y − x y-x yx均不包含在集合 s s s中的整数对 ( x , y ) (x,y) (x,y)的个数。

数据范围

t ( 1 ≤ t ≤ 2 × 1 0 4 ) t(1≤t≤2\times 10^4) t(1t2×104)

n ( 1 ≤ n ≤ 3 × 1 0 5 ) n(1≤n≤3\times 10^5) n(1n3×105)

c ( 1 ≤ c ≤ 1 0 9 ) c(1\le c\le 10^9) c(1c109)

思路

容斥。

合格的整数对=满足 x + y ∈ s x+y\in s x+ys+满足 y − x ∈ s y-x\in s yxs-既满足 x + y ∈ s x+y\in s x+ys又满足 y − x ∈ s y-x\in s yxs

参考代码

void solve() {ll n, c;cin >> n >> c;ll tot = (c + 1) * (c + 2) / 2;ll cnt0 = 0, cnt1 = 0;for (ll i = 0;i < n;i++) {ll x;cin >> x;tot -= x / 2 + 1;tot -= c + 1 - x;if (x & 1)cnt1++;else cnt0++;}tot += (cnt0 + 1) * cnt0 / 2 + cnt1 * (cnt1 + 1) / 2;cout << tot << endl;
}
http://www.lryc.cn/news/319322.html

相关文章:

  • 基于最小二乘法的太阳黑子活动模型参数辨识和预测matlab仿真
  • VSCode配置cuda C++编程代码提示的详细步骤
  • JUnit 面试题及答案整理,最新面试题
  • 使用Lua编写Wireshark解析ProtoBuf插件
  • ClickHouse副本节点数据损坏恢复
  • YOLOv9改进策略:注意力机制 | SimAM(无参Attention),效果秒杀CBAM、SE
  • 宝塔 安装对外服务Tomcat和JDK
  • rust最新版本安装-提高下载速度
  • 数据清洗与预处理:打造高质量数据分析基础
  • Linux服务器(Debian系)包含UOS安全相关巡检shell脚本
  • BS4网络提取selenium.chrome.WebDriver类的方法及属性
  • Prompt Engineering(提示工程)
  • 移远通信亮相AWE 2024,以科技力量推动智能家居产业加速发展
  • Java中上传数据的安全性探讨与实践
  • Leetcode 17. 电话号码的字母组合
  • 蓝桥杯单片机快速开发笔记——独立键盘
  • Swift 面试题及答案整理,最新面试题
  • 微信小程序上传图片c# asp.net mvc端接收案例
  • 57、服务攻防——应用协议RsyncSSHRDP漏洞批扫口令猜解
  • java:Druid工具类解析sql获取表名
  • MySQL--深入理解MVCC机制原理
  • 数据挖掘简介与应用领域概述
  • 瑞熙贝通打造智慧校园实验室安全综合管理平台
  • openstack调整虚拟机CPU 内存 磁盘 --来自gpt
  • 【IC设计】Verilog线性序列机点灯案例(三)(小梅哥课程)
  • 【打工日常】使用Docker部署团队协作文档工具
  • (一)Neo4j下载安装以及初次使用
  • QT for Mcu的学习建议
  • 【C语言初阶(五)】数组
  • 词令微信小程序怎么添加到我的小程序?