Codeforces Round 968 (Div. 2)
题目链接:Codeforces Round 968 (Div. 2) - Codeforces
总结:C题想到了,但是写成shi了,出得有点慢。
A. Turtle and Good String
tag:签到
Solution:直接判断第一个字符是否与最后一个字符相等即可。
void solve(){
cin >> n;
string s;
cin >> s;
if (s[0] == s[n - 1]){
cout << "No\n";
}
else{
cout << "YES\n";
}
}
B. Turtle and Piggy Are Playing a Game 2
tag:博弈论
Solution:显然每次操作要么是删除最小值,要么是删除最大值。排序后输出中间值即可。
void solve(){
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i ++){
cin >> a[i];
}
sort(a.begin(), a.end());
cout << a[n / 2] << endl;
}
C. Turtle and Good Pairs
tag:思维
Description:给定一个字符串\(s\),对于一对整数\((i, j)\),当\(si == sj\)或者存在一个整数\(k\),使得\(s_k != s_{k + 1}\),且\(s_k != s_i || s_{k + 1} != s_j\),\((i, j)\)为一对好的配对。将字符串重排,使好的配对数最大。
Solution:我们令\(k == i\),那么只要\(s_{i + 1} != s_{i} 且 s_{i + 1} != s_{j}\)即可,那么显然我们需要尽可能多的相邻两个字符不同的组合即尽可能使相邻两个字符不同。
- 其实只需要按顺序排列字符即可,多的字符全放在后面。
Competing:没仔细想,认为尽可能使相邻字符不同,因此需要判断出现次数最多的字符。
void solve(){
cin >> n;
cin >> s;
int ma = 0; // 出现次数最多的字符
char c;
map<char, int> mp;
vector<int> a(26);
for (int i = 0; i < n; i ++){
mp[s[i]] ++;
if (mp[s[i]] > ma){
ma = mp[s[i]];
c = s[i];
}
a[s[i] - 'a'] ++;
}
if (ma < n - ma + 1){
string ans = "";
int c = 0;
while (c < n){
for (int i = 0; i < 26; i ++){
if (a[i]){
a[i] --;
ans += char(i + 'a');
c ++;
}
}
}
cout << ans << endl;
}
else{
string ans = "";
int cnt = 0;
a[c - 'a'] = 0;
bool flag = true;
while (cnt < n && flag){
flag = false;
for (int i = 0; i < 26; i ++){
if (a[i]){
a[i] --;
ans += c;
ma --;
ans += char(i + 'a');
cnt ++;
flag = true;
}
}
}
while (ma){
ans += c;
ma --;
}
cout << ans << endl;
}
}
D1. Turtle and a MEX Problem (Easy Version)
tag:思维
Description:给定\(n\)个序列,以开始有一个非负整数\(x\):
- 每次操作可以任选一个序列,令\(x = mex(x, a_1, a_2, ..., a_n)\)。即\(f(x)\)为初始值为\(x\),操作之后可以得到的最大值。
- 给定一个\(m\),求\(\sum_{0}^{m}f(m)\)。
Solution:对于每个序列,我们最多操作两次,可以得到每个序列的第二个\(mex2\)。那么当\(x\)小于最大的\(mex2\)时,将其变成\(mex2\),否则使用\(x\)本身。
void solve(){
cin >> n >> m;
vector<pii> a(n);
int ma = 0;
for (int i = 0; i < n; i ++){
int len;
cin >> len;
vector<int> t(len + 10);
for (int j = 0; j < len; j ++){
int x;
cin >> x;
if (x < len + 10)
t[x] = 1;
}
int c = 1;
for (int j = 0; j <= len + 5 && c <= 2; j ++){
if (!t[j] && c == 1){
a[i].fi = j;
c ++;
}
else if (!t[j]){
c ++;
a[i].se = j;
ma = max(ma, j);
break;
}
}
}
int ans = 0;
if (m <= ma){
ans += (m + 1) * ma;
}
else{
ans += (ma + 1) * ma;
ans += (ma + 1 + m) * (m - ma) / 2;
}
cout << ans << endl;
}
D2. Turtle and a MEX Problem (Hard Version)
tag:思维
Solution:和D1的唯一区别时,在一次操作中每个序列最多使用一次。
- 对于第\(i\)个序列,我们建一条有向边\(u_i -> v_i\)。那么一次操作\(x\)可以沿着一条出边移动,或者移动到一个任意点\(u\),并断开它的出边。
- 我们先倒序处理一下,令\(b_i\)等于\(i\)能够到达的最大值,我们先倒序处理一下。
- 首先一个\(x\)的答案至少是\(f_x\),所有\(x\)的答案至少是\(\max_{1}^{n}u_i\);对于所有出度大于\(1\)的\(i\),\(x\)的答案至少是\(f_i\)。
- 实现步骤:倒序处理\(f_i\)、记录每个点的出度、记录度大于\(1\)的最大的\(f_i\)、记录最大的\(u_i\)。
void solve(){
cin >> n >> m;
vector<pii> a(n);
int ma = 0;
for (int i = 0; i < n; i ++){
int len;
cin >> len;
ma = max(ma, len);
vector<int> t(len + 10);
for (int j = 0; j < len; j ++){
int x;
cin >> x;
if (x < len + 10)
t[x] = 1;
}
int c = 1;
for (int j = 0; j <= len + 5 && c <= 2; j ++){ // 处理u,v的值
if (!t[j] && c == 1){
a[i].fi = j;
c ++;
}
else if (!t[j]){
c ++;
a[i].se = j;
break;
}
}
}
sort(a.begin(), a.end(),
[&](pii a, pii b){
return a.fi > b.fi;
});
int mma = 0; // 最大的ui
vector<int> b(ma + 10);
vector<int> chu(ma + 10);
for (auto [x, y] : a){ // 倒序处理
mma = max(mma, x);
int t = max(y, b[y]);
b[x] = max(b[x], t);
chu[x] ++;
}
int t2 = -1; // 度大于2的,最大的bi
for (auto [x, y] : a){
if (chu[x] >= 2 && b[x] > t2){
t2 = b[x];
}
}
int ans = 0;
for (int i = 0; i <= ma + 5 && i <= m; i ++){
b[i] = max({i, b[i], t2, mma});
ans += b[i];
}
if (m > ma + 5){
ans += (ma + 6 + m) * (m - ma - 5) / 2;
}
cout << ans << endl;
}
Codeforces Round 968 (Div. 2)的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- Slate文档编辑器-WrapNode数据结构与操作变换
Slate文档编辑器-WrapNode数据结构与操作变换 在之前我们聊到了一些关于slate富文本引擎的基本概念,并且对基于slate实现文档编辑器的一些插件化能力设计.类型拓展.具体方案等作了探讨, ...
- golang之热加载Fresh&air
Fresh 是一个命令行工具,每次保存Go或模版文件时,该工具都会生成或重新启动Web应用程序.Fresh将监视文件事件,并且每次创建/修改/删除文件时,Fresh都会生成并重新启动应用程序.如果go ...
- 2019GPLT
2019GPLT 7-2 6翻了 从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9:但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27.其他内容 ...
- HarmonyOS Next 入门实战 - 导航框架:HMRouter
基础知识 目前官方推荐的最佳解决方案,是官方对于Navigation导航组件的封装,使用更简单便捷.如果熟悉Navigation的话,使用起来很快上手. 首先先集成HMRouter模块 使用命令行安装 ...
- Shape文件格式
Shape文件格式 一个ESRI的shapefile数据包含一个主文件(.shp),一个索引文件(.shx)和一个dBASE(.dbf)表.主文件是直接访问的,变长记录的文件,每一条记录都描述一个形状 ...
- HTML 面试题
.code { background-color: rgba(246, 246, 246, 1); color: rgba(232, 62, 140, 1) } DOCTYPE的作用? DOCTYPE ...
- IOS多线程之NSOperation(1)
IOS多线程之NSOperation(1) NSOperation 是 OC 语言中基于 GCD 的面向对象的封装: 提供了一些用 GCD 不好实现的功能: 线程的生命周期由系统自动管理. NSOpe ...
- 【原创】xenomai环境下开源实时数控系统LinuxCNC编译安装
linuxcnc 在xenomai下的构建简单记录,参考链接https://www.linuxcnc.org/docs/devel/html/code/building-linuxcnc.html 1 ...
- maven打包时跳过TEST的方式汇总
使用maven打包时如何跳过test,有以下几种方式 针对spring项目 <plugin> <groupId>org.apache.maven.plugins</gro ...
- Qt编写物联网管理平台38-多种数据库支持
一.前言 本系统设计之初就要求支持多种不同的数据库,比如sqlite.mysql.postgres.sqlserver等,甚至包括国产数据库比如人大金仓kingbase等,(由于现在国产化的大力推进, ...