B. Minimum Ternary String (这个B有点狠)
1 second
256 megabytes
standard input
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 two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" →→ "100210";
- "010210" →→ "001210";
- "010210" →→ "010120";
- "010210" →→ "010201".
Note than you cannot swap "02" →→ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1≤i≤|a|1≤i≤|a|, where|s||s| is the length of the string ss) such that for every j<ij<i holds aj=bjaj=bj, and ai<biai<bi.
The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
100210
001120
11222121
11112222
20
20
这场CF abcd题 我就觉得B题最难
这个题目卡了我好久好久 ,全是写BUG
代码有点毒瘤
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
const int INF = 0x3fffffff;
typedef long long LL;
string s;
int sum0[maxn], sum1[maxn], sum2[maxn], vis[maxn];
vector<int>a;
int main() {
cin >> s;
if (s[] == '') sum0[] = ;
if (s[] == '') sum1[] = ;
if (s[] == '') sum2[] = ;
for (int i = ; i < s.size() ; i++) {
if (s[i] == '') sum0[i + ] = sum0[i] + , sum1[i + ] = sum1[i], sum2[i + ] = sum2[i];
if (s[i] == '') sum1[i + ] = sum1[i] + , sum0[i + ] = sum0[i], sum2[i + ] = sum2[i];
if (s[i] == '') sum2[i + ] = sum2[i] + , sum0[i + ] = sum0[i], sum1[i + ] = sum1[i];
}
int cnt = ;
int len = s.size();
for (int i = ; i < len ; i++) {
if (s[i] == '') {
for (int j = ; j < sum0[i]; j++) a.push_back();
for (int j = ; j < sum1[len] ; j++) a.push_back();
for (int j = i ; j < s.size(); j++) {
if (s[j] == '') continue;
if (s[j] == '') a.push_back();
if (s[j] == '')a.push_back();
}
cnt = ;
break;
}
}
if (cnt == ) {
for (int i = ; i < sum0[len] ; i++) printf("");
for (int i = ; i < sum1[len] ; i++) printf("");
} else {
for (int i = ; i < a.size() ; i++) printf("%d", a[i]);
}
return ;
}
B. Minimum Ternary String (这个B有点狠)的更多相关文章
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- CF1009B Minimum Ternary String 思维
Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces - 1009B Minimum Ternary String
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). ...
- Codeforces ~ 1009B ~ Minimum Ternary String (思维)
题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...
- Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String
题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...
- Balanced Ternary String CodeForces - 1102D (贪心+思维)
You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...
- 牛客多校第四场 A Ternary String
题目描述 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a t ...
- 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]
题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...
- 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
随机推荐
- oracle监听配置
在listener.ora文件中指定监听的实例名和修改ip地址: 查看实例名:[localhost$] echo $ORACLE_SID LISTENER = (DESCRIPTION_LIST = ...
- 10 TCP 传输控制协议 UDP区别
1.tcp和udp区别 2.TCP通信模型 生活中的电话机 如果想让别人能更够打通咱们的电话获取相应服务的话,需要做一下几件事情: 买个手机 插上手机卡 设计手机为正常接听状态(即能够响铃) 静静的等 ...
- Java检测端口的占用情况
突然间想到这个问题,在网上搜了一下 http://blog.csdn.net/danieluk/article/details/18518175 网上有很多文章都是用上面那个方法来解决这个问题的,总感 ...
- BZOJ 1968 [Ahoi2005]COMMON 约数研究:数学【思维题】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1968 题意: 设f(x) = x约数的个数.如:12的约数有1,2,3,4,6,12,所以 ...
- Sql面试题之三(难度:简单| 含答案)
Sql面试题之三(难度:简单| 含答案) 答案: .SELECT B.name, B.Depart T.Content FROM B, T WHERE ( T.Content = '税法培训' and ...
- 问题 D: 约数的个数
问题 D: 约数的个数 时间限制: 1 Sec 内存限制: 32 MB提交: 272 解决: 90[提交][状态][讨论版][命题人:外部导入] 题目描述 输入n个整数,依次输出每个数的约数的个数 ...
- 学习人工智能的第六个月[深度学习[Deep Learning,DL]]
这个月阅读了论文[Partial Adversarial Domain Adaptation-eccv18],文章着眼于源域标签空间包含目标域标签空间的场景,在域对抗神经网络的基础上提出了部分对抗域适 ...
- Browser-Solidity的本地安装及使用介绍
Browser-Solidity的本地安装及使用介绍 正所谓工欲善其事必先利其器,巧妇也难为无米之炊,所以在学习智能合约之前,必须要先把工具准备好.Browser-Solidity 是 Ethereu ...
- sql 条件插入
原普通插入语句: insert into seriestable_upload values(New.SeriesID,0); 加条件后:(当不存在该条数据插入) insert into custom ...
- C++ 中神奇的头文件,懒人专用
今天在做题的时候,偶然发现了一种神奇头文件.他的使用方法以及内容如下: #include <bits/stdc++.h> // C++ includes used for precompi ...