题目链接:http://codeforces.com/contest/1009/problem/B

解题心得:

  • 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就是相邻的01交换,12交换,不可以02交换。最后需要输出字典序最小的字符串。
  • 其实想想就很容易明白在字符串中1是可以随便移动的,所以可以把字符串中的1全删除,就只剩下02两种字符,这两种字符的相对位置不可以改变。然后把所有的1插在第一个02之间。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+; char s[maxn], ans[maxn];
int len, cnt_1;
void init(){
scanf("%s",s);
len = strlen(s);
for(int i=;i<len;i++)
if(s[i] == '')
cnt_1++;
} void solve(){
if(cnt_1 == len) {//只有1的情况
printf("%s",s);
return ;
}
int tot = ,i,j;
for(i=;i<len;i++) {//找到第一个02中间
if(s[i] == '') {
ans[tot++] = s[i];
} else if(s[i] == ''){
continue;
} else {
while(cnt_1--) {
ans[tot++] = '';
}
break;
}
}
for(j=i;j<len;j++) {
if(s[j] == '')
continue;
else
ans[tot++] = s[j];
}
int len_ans = strlen(ans);
if(len_ans < len){//只有01的情况补1
for(int j=len_ans;j<len;j++)
ans[tot++] = '';
}
ans[tot] = '\0';
printf("%s", ans);
} int main() {
init();
solve();
}

Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String的更多相关文章

  1. Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

    题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ...

  2. Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph

    题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ...

  3. Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)

    题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...

  4. Educational Codeforces Round 47 (Rated for Div. 2) :A. Game Shopping

    题目链接:http://codeforces.com/contest/1009/problem/A 解题心得: 题意就是给你两个数列c,a,你需要从c中选择一个子串从a头开始匹配,要求子串中的连续的前 ...

  5. Educational Codeforces Round 47 (Rated for Div. 2) 题解

    题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ...

  6. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  7. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  8. Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition

    C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...

  9. Educational Codeforces Round 47 (Rated for Div. 2)E.Intercity Travelling

    题目链接 大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1​+a2​+...+ak​,休息后a1a_1a1​开始计, ...

随机推荐

  1. March 24 2017 Week 12 Friday

    Our lives are brief, that is why it's important to search for meaning. 人生短暂,所以才要寻找它的意义. What can we ...

  2. python入门8 输入输出

    输入 input() 输出 print() #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 输入输出 & ...

  3. chpasswd

    功能说明:从标准输入中读取一定格式的用户名.密码来批量更新用户的密码,其格式为 “用户名:密码”. 参数选项:-e 默认格式是明文密码,使用-e参数则需要加密的密码.

  4. libevent-select模型分析

    下面内容为windows下select模型分析,原博客链接 http://blog.csdn.net/fish_55_66/article/details/50352080 https://www.c ...

  5. 【洛谷2709】小B的询问(莫队模板题)

    点此看题面 大致题意: 有一个长度为\(N\)的序列,每个数字在\(1\sim K\)之间,有\(M\)个询问,每个询问给你一个区间,让你求出\(\sum_{i=1}^K c(i)^2\),其中\(c ...

  6. 【洛谷P1108】低价购买

    低价购买 题目链接 n<=5000 n^2的算法是可以接受的 第一个数字显然是求最长下降子序列,可以n^2或nlognDP 要求方案数,可以在n^2算法中做一些修改,DP求方案数 dp[i]表示 ...

  7. 【洛谷P2324】[SCOI2005]骑士精神

    骑士精神 题目链接 #include<iostream> #include<cstdio> using namespace std; int t,MAXD,sx,sy; ][] ...

  8. Android学习笔记_61_手机安全卫士知识点归纳(1)状态/形状图形 GPS 设备管理器DeviceAdminReceiver ImageView属性

    1.在做程序自动安装更新的时候 ,必须保证程序的签名和包名是相同.  C:\Documents and Settings\zehua\.android  \ debug.keystore  debug ...

  9. artTemplate 根据key循环对象

    artTemplate 根据key循环对象var dataObj={ data:{ a:{ name:'卡卡', age:10 }, b:{ name:'卡卡', age:10 }, c:{ name ...

  10. [Windows]ping itsafe&环境变量

    (1)when you ping a computer from itsafe,the ping command should return the local IP address. (2)wind ...