Codeforces ~ 1009B ~ Minimum Ternary String (思维)
题意
给你一个只含有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 (思维)的更多相关文章
- CodeForces - 1009B Minimum Ternary String
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). ...
- CF1009B Minimum Ternary String 思维
Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- B. Minimum Ternary String (这个B有点狠)
B. Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String
题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...
- Codeforces 1221F Game With String 思维题
题意:有两个人玩游戏,游戏规则如下:有一个长度为n的字符串,这个字符串由 . 和 X 构成,Alice可以选择a个连续的 . 把它们变成X, Bob可以选择连续的b个 . 把它们变成X.题目中保证a ...
- Balanced Ternary String CodeForces - 1102D (贪心+思维)
You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...
- Balanced Ternary String(贪心+思维)
题目链接:Balanced Ternary String 题目大意:给一个字符串,这个字符串只由0,1,2构成,然后让替换字符,使得在替换字符次数最少的前提下,使新获得的字符串中0,1,2 这三个字符 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
随机推荐
- LaTeX数学公式基础
LaTeX数学公式 参考:https://www.cnblogs.com/Sinte-Beuve/p/6160905.html 原博客显示有点问题,重新搬运整理LaTeX数学公式部分的基本用法 基础 ...
- Python 面向对象 (进阶篇)
<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使用(可 ...
- 使用Javascript Ajax 通信操作JSON数据 [下]
上一篇文章我们获得后台数据库的数据后转换成json格式然后返回到前台,但只是返回的一位数组,这次我们返回二维和三维数组和对象. 前台代码shizhan.html: <!DOCTYPE html& ...
- C++面向对象类的实例题目五
题目描述: 编写一个程序,采用一个类求n!,并输出5!的值. 程序代码: #include<iostream> using namespace std; class CFactorial ...
- 如何把VS2015中本地的一个项目建立远程的Git Repository
在项目开发中,我在本地自己电脑上用VS2015建立了一个项目,比如项目名字叫做Luke.Test 那么,接下来,我如何把这个项目签入到远程的Git Repository里去呢. 方法如下 先进入远程R ...
- Spring第六篇---AOP
接着Spring第五篇讲 我们今天将叙述以下几个知识点 1 什么是AOP AOP 是一种思想 横向重复 纵向抽取 在软件业,AOP为Aspect Oriented Programming的缩写,意 ...
- 《Spring实战》-2
装配Bean 1.装配wiring,即创建应用对象之间的协作关系的行为,者也是依赖注入的本质. 2.创建Spring配置 从Sring3.0开始,Spring容器提供了两种配置Bean的方式: XML ...
- Java流机制详解
转自http://blog.csdn.net/qq_16558621/article/details/51377887 http://www.cr173.com/html/18666_1.html
- HttpWebRequest,HttpWebResponse 使用
目的:工作中已经两次使用了,特此记录一下,并写好注释 /// <summary> /// HttpWebRequest的基本配置 /// </summary> public c ...
- IDEA 基本操作
1.IDEA 编译的JDK问题 点击出错的模块 将这个改成8,但是改了这个还是不行,项目一编译他有回去了. 正确的做法: 在跟pom.xml 中增加如下代码: <build> <pl ...