Codeforces Round #767 (Div. 2) c d, 巧妙标记
这两个题不错, 第一个需要考虑后面,就先标记完, 从前遍历挨个除去标记
第二个需要考虑前面, 就开始初始化为0, 从前遍历挨个标记
C. Meximum Array
题意: 给出n个数, 把n个数分成任意份, 使得每一段mex结果尽量的大, 其次连起来数尽量的长
mex = 一组数最小且不存在于序列中的数, 包括0
题解: 既然要每段的mex尽量大, 那么后面加再多数 mex都不会变, 那么后面都是小于或大于mex, 即这一段序列后面没有mex
#include <bits/stdc++.h> using namespace std; const int N = 2e5+10;
int a[N], cnt[N];
bool st[N];
int main()
{
int t;
cin >> t;
while(t --)
{
vector<int> res;
int n;
cin >> n;
for(int i = 0; i < n; i ++)cnt[i]=0;
for(int i = 0; i < n; i ++)cin >> a[i], cnt[a[i]]++, st[i]=0;
/*
cnt //后面的所有数的次数, 用于判断后面还有没有更大的数
st //当前一小段序列谁出现过
*/
int mex = 0;//当前一小段序列的mex
for(int i = 0; i < n; i ++)
{
st[a[i]]=1;
while(st[mex])mex++;//找到从前到后第一个没有的数, 求mex
cnt[a[i]]--;//后面还有几个这个数
if(cnt[mex]<=0)//后面也没有这个数,那么再往后也没用了
{
res.push_back(mex);
for(int j = mex-1; j >= 0; j --)//为下一段序列初始化
{
st[j]=0;
}
mex=0;
}
}
cout << res.size() << endl;
for(int i = 0; i < res.size(); i ++)cout << res[i] << ' ';
cout << endl;
}
return 0;
}
D. Peculiar Movie Preferences
题意: 米海计划看一部电影。他只喜欢回文电影,所以他想跳过一些(可能零)场景,使电影的其余部分回文, 每个场景长度不超过三。
题解: 无非两种情况1.本身是回文2.遍历时前面有一串可以和他构成回文(从前往后遍历)
所以从前往后遍历的话, 只看它是否能够成为后缀
/*
做后缀:
倒过来加一个数
倒过来去一个数
倒过来 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int tx[4] = {-1,0,1,0}, ty[4] = {0,1,0,-1}; typedef pair<int,int> PII; const int N = 1e5+10;
string a[N];
map<string,bool> mp; bool solve()
{
mp.clear();//map用法
int n;
cin >> n;
bool f = 0;
for(int i = 0; i <n ; i ++)
{ cin >>a[i];
mp[a[i]]=1;
string s = a[i];
reverse(s.begin(), s.end());
if(s.size()==1 || s.size()==2&&s[0]==s[1] || mp[s])f=1;//本身是回文 if(mp[s.substr(0,s.size()-1)])f=1;//倒过来去一个数 for(char i = 'a'; i <= 'z'; i ++)//倒过来加一个数
if(mp[s+i])
f= 1;
}
return f;
}
int main()
{
int t;
cin >> t;
while(t --)
{
if(solve())puts("YES");
else puts("NO");
}
}
Codeforces Round #767 (Div. 2) c d, 巧妙标记的更多相关文章
- Codeforces Round #767 (Div. 2)——B. GCD Arrays
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他 ...
- Codeforces Round #260 (Div. 2) A , B , C 标记,找规律 , dp
A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 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 #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- Codeforces Round #499 (Div. 1)
Codeforces Round #499 (Div. 1) https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm s ...
- Codeforces Round #577 (Div. 2) D. Treasure Hunting
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
随机推荐
- mysql优化参数 (汇总)
1 如下为128G内存32线程处理器的mariadb配置参数优化: [client]#password= your_passwordport= 3306 socket= /tmp/mysql.sock ...
- RabbitMQ在开发环境搭建-转载
1.安装erlang. rabbitmq 安装需要erlang 的支持,所有安装rabbitmq 之前需要现安装erlang.下载 erlang: https://www.erlang.org/dow ...
- Java中获取applicationcontext(应用上下文)
package com.wl.iwbservice.util; import org.springframework.beans.BeansException; import org.springfr ...
- tomcat启动 ssm项目出现乱码的解决
0.乱码产生原因:编码和解码的方式是不同 1.出现乱码的解决方式[推荐]: 在tomcat 的配置文件web.xml 中添加上请求编码过滤器: <!-- 请求编码过滤器 --> <f ...
- 论文翻译:2021_Joint Online Multichannel Acoustic Echo Cancellation, Speech Dereverberation and Source Separation
论文地址:https://arxiv.53yu.com/abs/2104.04325 联合在线多通道声学回声消除.语音去混响和声源分离 摘要: 本文提出了一种联合声源分离算法,可同时减少声学回声.混响 ...
- 学习廖雪峰的git教程6--版本控制
1git log 查看提交的版本 2git reset --hard HEAD^回退到上一个版本 3git reset --hard 版本号 回到某一个版本
- hanoi(老汉诺塔问题新思维)
#include <stdio.h> //第一个塔为初始塔,中间的塔为借用塔,最后一个塔为目标塔 int i=1;//记录步数 void move(int n, char from,cha ...
- 简述synchronized和java.util.concurrent.locks.Lock的异同 ?
主要相同点:Lock能完成synchronized所实现的所有功能 主要不同点:Lock有比synchronized更精确的线程语义和更好的性能.synchronized会自动释放锁,而Lock一定要 ...
- python实现AES加密、解密
AES加密方式有五种:ECB, CBC, CTR, CFB, OFB 从安全性角度推荐CBC加密方法,本文介绍了CBC,ECB两种加密方法的python实现 python 在 Windows下使用AE ...
- Spring 框架中的单例 bean 是线程安全的吗?
不,Spring 框架中的单例 bean 不是线程安全的.