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 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.

Input

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).

Output

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

Examples
input

Copy
100210
output

Copy
001120
input

Copy
11222121
output

Copy
11112222
input

Copy
20
output

Copy
20

遇见这个特别恶心的思维题,打教育场的我直接被这题给教育了QAQ

题意:给你一个由0 1 2 构成的字符串,其中0可以和1、1可以和2交换位置,求交换后字典序最小的的串

题解:我们来冷静分析一波,1可以和0换,可以和1换,那么1在这个字符串当中就可以任意滑动,要想字符串的字典序最小

那么所有的1肯定会在第一个出现2前面,要是没有2,那么最后的字符串一定会是000111的形式,如果有2的话,第一个2后面1一定全部在第一个2的前面

第一个二后面的0和2实际上就不会变化.

代码如下:

#include <bits/stdc++.h>
using namespace std;
int main(){
string str;
cin>>str;
int len=str.size();
int pos;
int flag=;
int num0=,num1=;
for(int i=;i<len;i++){
if(str[i]==''&&flag==){
flag=;
pos=i;
}
if(str[i]=='') num1++;
if(str[i]==''&&flag==) num0++;
}
for(int i=;i<num0;i++){
cout<<"";
}
for(int i=;i<num1;i++){
cout<<"";
}
if(flag==){
for(int i=pos;i<len;i++){
if(str[i]=='') continue;
cout<<str[i];
}
}
cout<<endl;
return ;
}

codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题的更多相关文章

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

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

  2. CF1009B Minimum Ternary String 思维

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

  3. CodeForces - 1009B Minimum Ternary String

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

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

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

  5. Codeforces ~ 1009B ~ Minimum Ternary String (思维)

    题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...

  6. codeforces round 472(DIV2)D Riverside Curio题解(思维题)

    题目传送门:http://codeforces.com/contest/957/problem/D 题意大致是这样的:有一个水池,每天都有一个水位(一个整数).每天都会在这一天的水位上划线(如果这个水 ...

  7. C. Meaningless Operations Codeforces Global Round 1 异或与运算,思维题

    C. Meaningless Operations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

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

随机推荐

  1. django+xadmin在线教育平台(八)

    4-5 user modesl.py设计 循环引用: 设计app时每个app都有model   mark 如图:我们在user中定义usercourse记录用户学习的课程.会有两个外键:user和co ...

  2. VMware运行时“内部错误”的解决方法

    解决方法:打开虚拟机实体目录,如下:发现有两个虚拟机配置文件,一个文件大小为4KB,另一个为空.现在虚拟机默认使用为空的配置文件了. 将大小为空的虚拟机配置文件删除掉,然后将另一个配置文件重名命. 接 ...

  3. JSONArray.fromObject不执行且不报错问题的解决

    今天在写javaweb工程的时候需要向前台传json格式的数据,用到了json-lib-2.4-jdk15.jar等一系列包,然而却出现如下状况: CityBean是一个javaBean,我们看到,控 ...

  4. 【转载】char*,const char*和string 三者转换

    本文转自 http://blog.csdn.net/perfumekristy/article/details/7027678 const char* 和string 转换 const char*转换 ...

  5. Myeclipse上配置weblogic11g(10.3.6)的方法教程

    1.在windows-perferences-MyEclipse-Servers-weblogic下找到weblogic10.X 2.按照参考我上面的附图填入weblogic的相关路径(如果你是完全按 ...

  6. Gson转Map时,Int会变成double解决方法

    package com.cdy.demo; import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; ...

  7. 使用CSS3制作各种形状

    CSS3的一个非常酷的特性是允许我们创建各种规则和不规则形状的图形,从而可以减少图片的使用.以前只能在Photoshop等图像编辑软件中制作的复杂图形现在使用CSS3就可以完成了.通过使用新的CSS属 ...

  8. 2139: road

    把a[i], b[i]分开来排序 对应位置上的点连边 感性理解这是最小的 会连出若干个环 要使得若干个环连成大环 令a[i]向b[i - 1] 连边 易证一定能使图联通 感性理解这也是最小的 #inc ...

  9. 学习网络请求返回json对应的model

    原来泛型可以这样用: 网络返回基类,返回一个code,msg,body,其中body不确定,所以,我们把它写成泛型 import org.json.JSONObject; /** * 网络请求的基类 ...

  10. 使用Oracle绿色客户端(InstantClient)连接远程Oracle的配置方法

    非常简单的配置,网上一搜,有很多,但是还是想记录下来,说不定以后需要了,直接进自己的博客看看也好啊. 下载了PLSQL Developer 11,安装好了发现不能连接远程数据库,但是又不想安装orac ...