当前位置:网站首页>Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
2022-07-26 22:49:00 【ZaneBobo】
一.题意
tina具有改变字符串的能力,他能将主字符串的一部分字符变成另一种字符。
每次主字符串初始是一个字符,然后最终tina通过运用自己改变字符串内某段字符的能力,不断对这个本来只有一个字符的字符串进行变化,将这个字符变成了一个字符串。
有T组测试数据,每组测试数据给到你一个整数n,然后再给你2*n个字符串,这些字符串一部分是被改变的一段字符,一部分是将要改变的字符改变成的一段字符,没有固定顺序随机给出。
然后在2*n+1行给出了最终成为的字符串。
要求你猜出这个字符串最初是哪个字符。
二.思路
先说下结论,结论是在2*n+1所有字符串中出现次数为奇数的字符那就是最初的字符。
证明:我们来看一下每个被增添上来的字符的出现频率,不管是它单独作为替换字符去替换一段字符串,还是他作为替换字符段内的一个字符去替换现有的字符段,它一定是出现偶数次的,为什么呢?我们分两种情况:
①它被增添上来了,然后又被删掉了。这样的话它一次是作为改变成为的一段字符的一个字符,一次是作为被删字符段内的一个字符,此个字符一定会出现2次。
②它被增添上来了,没被删掉。这样的话它一次是作为改变成为的一段字符的一个字符,一次是作为最终结果的一个字符,因为他没被删掉嘛,所以也是偶数次。
但是最初那个字符一定会作为被改变的字符多出现1次。
所以最初那个字符一定出现奇数次,而其他字符一定出现偶数次。
其实如果把每个字符就算他长得一样也看做不一样的话,也就是最开始的那个字符会出现1次,其他都是2次.
三.代码
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
map<char,int> cnt;
void solve()
{
int n;
cin>>n;
cnt.clear();
for(int i=1;i<=2*n+1;i++)
{
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
cnt[s[i]]++;
}
}
for(char i='a';i<='z';i++)
{
if(cnt[i]&1)
{
cout<<i<<endl;
return;
}
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
solve();
}
}边栏推荐
猜你喜欢

Dynamic routing rip protocol experiment

TIM输出比较——PWM

NAT network address translation experiment

7.13 Weilai approved the written examination in advance

Connect mysql detailed graphic operations in ECs docker (all)

Flink1.13.6 detailed deployment method

MySQL课程1.简单命令行--简单记录 欢迎补充纠错
![[explain C language in detail] takes you to play with the choice (Branch) structure](/img/ca/7ee9f62a2478785c97684c7a0cc749.png)
[explain C language in detail] takes you to play with the choice (Branch) structure

OGeek Meetup第一期,携手CubeFS火热来袭

VLAN原理简述、具体实验配置
随机推荐
初识C语言(2)
HCIA基础知识(1)
Experiment of total connection and star topology of mGRE
Introduction to STM32 lesson 1
FID index reproduction step on the pit to avoid the pit text generation image FID quantitative experiment whole process reproduction (FR é Chet inception distance) quantitative evaluation experiment s
Pseudo class of a element
C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!
6.28 flush written test
Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)
Realize data interaction between two apps through fileprovider
机械硬盘选购指南——从选购经历谈起
Unity Huatuo revolutionary hot update series [1]
通过对射式红外传感器计次实验讲解EXTI中断
7.8 锐捷网络笔试
Beyond hidden display ellipsis
Specify that SQL only supports select syntax
[FPGA tutorial case 28] one of DDS direct digital frequency synthesizers based on FPGA -- principle introduction
第三讲--GPIO输入输出库函数使用以及相关例程
STM32 HAL库串口(UART/USART)调试经验(一)——串口通信基础知识+HAL库代码理解
Simple application of rip V2 (V2 configuration, announcement, manual summary, ripv2 authentication, silent interface, accelerating convergence)