当前位置:网站首页>#796 Div.2 C. Manipulating History 思维
#796 Div.2 C. Manipulating History 思维
2022-06-27 22:15:00 【Strezia】
link
思维
题意
现有一个串 s s s, 初始只含一个字母,给出 2 n 2n 2n 个串,每次可以从中选2个串 t 1 , t 2 t_1,t_2 t1,t2,将 s s s 中子串 t 1 t_1 t1 替换为 t 2 t_2 t2,重复 n n n 次,现给出这 2 n 2n 2n 个串以及最终结果,求初始字母。
思路
统计给出的 2 n + 1 2n+1 2n+1 个串中每个字母的出现次数,为奇数的那个即为初始字母。
因为每个字母一定会在它加入的时候出现一次,然后在被删除(或保留到了最后)时出现一次。也就是一定出现了偶数次,只有初始字母在被替换的时候加入的一次。
代码
void solve() {
int n;
cin >> n;
vector<int> cnt(30);
for(int i = 1; i <= 2 * n + 1; i++) {
string s;
cin >> s;
for(auto i : s) {
cnt[i - 'a']++;
}
}
for(int i = 0; i < 30; i++) {
if(cnt[i] & 1) {
cout << char(i + 'a') << endl;
return;
}
}
}
边栏推荐
- Recyclerview implements grouping effects in a variety of ways
- 炼金术(3): 怎样做好1个业务流程的接口对接
- [VIM] tutorial, common commands, efficient use of vim editor
- MySQL企业级参数调优实践分享
- 一个人可以到几家证券公司开户?开户安全吗
- 炼金术(4): 程序员的心智模型
- Alchemy (9): simple but not simple, never-ending test -- always_ run
- Squid代理服务器(缓存加速之Web缓存层)
- 单片机之IIC通信协议「建议收藏」
- 自定义MySQL连接池
猜你喜欢
随机推荐
Msp430f5529 MCU reads gy-906 infrared temperature sensor
投资场内ETF基金是靠谱吗,场内ETF基金安全吗
内网IP和公网IP的区别及作用
数据仓库入门介绍
Mongodb- install a mongodb database locally on the windows computer
Hcip/hcie Routing & Switching / datacom Reference Dictionary Series (19) comprehensive summary of PKI knowledge points (public key infrastructure)
本地可视化工具连接阿里云centOS服务器的redis
RNA-seq入门实战(一):上游数据下载、格式转化和质控清洗
[digital ic/fpga] detect the position of the last matching sequence
How many securities companies can a person open an account? Is it safe to open an account
Flutter series: Transformers in flutter
Sécurité, économie de carburant et protection de l'environnement chameau
100 questions for an enterprise architect interview
Arduino UNO通过电容的直接检测实现简易触摸开关
自定义MySQL连接池
券商买股票用什么app是比较好的,比较安全的
炼金术(7): 何以解忧,唯有重构
Transmitting and receiving antenna pattern
吴恩达《机器学习》课程总结(11)_支持向量机
[untitled]







![软件工程作业设计(1): [个人项目] 实现一个日志查看页面](/img/95/0c3f0dde16d220ddecb5758a4c31e7.png)
