当前位置:网站首页>#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;
}
}
}
边栏推荐
- 互联网业衍生出来了新的技术,新的模式,新的产业类型
- 软件工程作业设计(1): [个人项目] 实现一个日志查看页面
- TIME_WAIT过多的解决办法
- Transmitting and receiving antenna pattern
- 云原生运维文章计划
- The development of the Internet provides new solutions for industrial transformation
- Software engineering job design (1): [personal project] implements a log view page
- 2022 PMP project management examination agile knowledge points (3)
- 吴恩达《机器学习》课程总结(13)_聚类
- Quickly master grep commands and regular expressions
猜你喜欢

What is promise

Summary of wuenda's machine learning course (14)_ Dimensionality reduction

什么是cookie,以及v-htm的安全性隐患

Promise是什么
![计数质数[枚举 -> 空间换时间]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
计数质数[枚举 -> 空间换时间]
最新MySQL高级SQL语句大全

Mongodb- install a mongodb database locally on the windows computer

Sword finger offer 61 Shunzi in playing cards

Leetcode 720. 词典中最长的单词(为啥感觉这道题很难?)

免费、好用、强大的开源笔记软件综合评测
随机推荐
吴恩达《机器学习》课程总结(13)_聚类
internship:业务流程初识
Which securities company is better and safer to open an account for stock speculation
Code neatness -- function
Arduino UNO通过电容的直接检测实现简易触摸开关
What is promise
【无标题】
Sell notes | brief introduction to video text pre training
夏日的晚会
Feign通过自定义注解实现路径的转义
Understand the basic structure of wechat applet project
#795 Div.2 D. Max GEQ Sum 单调栈
RNA SEQ introduction practice (I): upstream data download, format conversion and quality control cleaning
Is the securities registration account safe? Is there any risk?
Scu| gait switching and target navigation of micro swimming robot through deep reinforcement learning
Logging log usage
免费、好用、强大的开源笔记软件综合评测
plot_model报错:没有安装pydot, graphviz
数仓的字符截取三胞胎:substrb、substr、substring
VirtualBox extended dynamic disk size pit