题解 CF1354B 【Ternary String】】的更多相关文章

题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a ternary string s which can self-reproduce. Every second, a digit 0 is inserted after every 1 in the str…
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之后第一个数字消失.求最后为空串需要多少秒. 题解: (1)如果在消除一个 0 前经过了 n 秒,那么消掉这个 0 需要 n + 1 秒. (2)如果在消除一个 1 前经过了 n 秒,那么消掉这个 1 与其产生的所有数需要 (n + 1) * 2 秒. (3)如果在消除一个 2 前经过了 n 秒,那么…
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a ternary string (it is a string which consists only…
You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings. Your task is to replace minimum number of characters in this string with other characters to obtain…
题目描述 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a ternary string s which can self-reproduce. Every second, a digit 0 is inserted after every 1 in the string, and then a digit 1 is inserted after every…
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (con…
B. Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap an…
Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any t…
题目链接:Balanced Ternary String 题目大意:给一个字符串,这个字符串只由0,1,2构成,然后让替换字符,使得在替换字符次数最少的前提下,使新获得的字符串中0,1,2 这三个字符的数目相同,并且新获得的字符串的字典序要尽可能的小: 直接数组做法:暴力遍历 /* */ # include <bits/stdc++.h> using namespace std; typedef long long ll; int n; ]; string s; int main() { io…
[题解]Rusty String [CF827E] 传送门:\(\text{Rusty String}\) \(\text{[CF827E]}\) [题目描述] 多组数据,每组数据给出一个由 \(V,K,?\) 三种字符组成的字符串,其中 \(?\) 可以替换为 \(V,K\) 中的任意一个,求替换后的字符串可以存在的循环周期有哪些. [分析] 乍一看像是带通配符的字符串匹配(不会的强烈建议去康康这个),由于字符集不大,按照套路就应该枚举两个字符 \(a \ne b\in\{V,K\}\),然后…