题意

给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12"变为"21","21"变为"12",问通过变换可以得到的字典序最小的串是什么?

题解

一开始天真的以为,我把所有的"10"变为"01",和所有的"21"变为"12"即可。

直到发现了201,20001这种数据,发现思路错了。

首先所有'1'一定能被交换到任意位置,'0'和'2'的相对位置不可能发生改变。

所以我们把所有的'1'放到第一个2的前面就行了。

AC代码:

#include <bits/stdc++.h>
using namespace std;
string s, ans;
int main()
{
cin >> s;
int one = ;
for (int i = ; i < s.size(); i++)
{
if (s[i] == '') ans += "";
if (s[i] == '') one++;
if (s[i] == '') ans += "";
}
bool flag = false;
for (int i = ; i < ans.size(); i++)
{
if (ans[i] == '' && !flag) flag = true, cout << string(one, '');
cout << ans[i];
}
if (!flag) cout << string(one, '');
return ;
}

Codeforces ~ 1009B ~ Minimum Ternary String (思维)的更多相关文章

  1. CodeForces - 1009B Minimum Ternary String

    You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). ...

  2. CF1009B Minimum Ternary String 思维

    Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  4. B. Minimum Ternary String (这个B有点狠)

    B. Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input sta ...

  5. Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String

    题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...

  6. Codeforces 1221F Game With String 思维题

    题意:有两个人玩游戏,游戏规则如下:有一个长度为n的字符串,这个字符串由 . 和 X 构成,Alice可以选择a个连续的 . 把它们变成X, Bob可以选择连续的b个 . 把它们变成X.题目中保证a ...

  7. Balanced Ternary String CodeForces - 1102D (贪心+思维)

    You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...

  8. Balanced Ternary String(贪心+思维)

    题目链接:Balanced Ternary String 题目大意:给一个字符串,这个字符串只由0,1,2构成,然后让替换字符,使得在替换字符次数最少的前提下,使新获得的字符串中0,1,2 这三个字符 ...

  9. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

随机推荐

  1. IDEA创建的Maven项目中 解决编写pom.xml没有提示

    问题如下 没有提示信息 解决方案 把Repositories中的配置更新成本地仓库 问题解决

  2. dubbo-admin打包和zookper安装

    1 首选安装Zookper,下载zookeeper-3.5.3-beta版本,在这里我主要演示这个:下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/ ...

  3. ROS Learning-002 beginner_Tutorials 如何添加ROS环境变量 和 如何更新ROS源代码

    ROS Indigo beginner_Tutorials 之 添加环境变量 和 更新ROS源代码的命令 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubu ...

  4. hBase-thrift 实践(java)

    参考官网: http://wiki.apache.org/hadoop/Hbase/ThriftApi 环境:hbase-0.98.1-cdh5.1.0,hadoop-2.3.0-cdh5.1.0,c ...

  5. Luogu 2737 [USACO4.1]麦香牛块Beef McNuggets

    NOIP2017 D1T1 的结论,两个数$a, b$所不能表示出的最大的数为$a * b - a - b$. 听了好几遍证明我还是不会 注意到本题中给出的数都非常小,所以最大不能表示出的数$\leq ...

  6. Comparator 排序

    例1: import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import ja ...

  7. Spring学习大纲

    1.BeanFactory 和 FactoryBean? 2.Spring IOC 的理解,其初始化过程? 3.BeanFactory 和 ApplicationContext? 4.Spring B ...

  8. 【Java学习】Java迭代器

    迭代器是一种模式,它可以使得对于序列类型的数据结构的遍历行为与被遍历的对象分离,即我们无需关心该序列的底层结构是什么样子的.只要拿到这个对象,使用迭代器就可以遍历这个对象的内部. 1.Iterator ...

  9. delphi xe6 让 ListView 在 Android 可回弹[根据龟山阿卍原创修改为xe6版本]

    Delphi XE6 找出 FMX.Platform.Android.pas 档案,并复制到自己的 Project 路径里,找到 GetScrollingBehaviour 函数,修改成如下: uni ...

  10. 简单的linux service(linux服务)编写,运行示例

    1.写一个简单小程序 #include<stdio.h> #include<stdlib.h> int main(int argc,char **argv) { while(1 ...