博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #572 (Div. 2) A.
阅读量:4556 次
发布时间:2019-06-08

本文共 2592 字,大约阅读时间需要 8 分钟。

A. Keanu Reeves

题目链接:

题目:

After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good.
We are given a string s
of length n consisting of only zeroes and ones. We need to cut s into minimal possible number of substrings s1,s2,…,sk such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings s1,s2,…,sk such that their concatenation (joining) equals s, i.e. s1+s2+⋯+sk=s
For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all 3
strings are good.
Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.
Input
The first line of the input contains a single integer n
(1≤n≤100) — the length of the string s
.
The second line contains the string s
of length n consisting only from zeros and ones.
Output
In the first line, output a single integer k(1≤k) — a minimal number of strings you have cut s into.
In the second line, output k
strings s1,s2,…,sk separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to s and all of them have to be good.
If there are multiple answers, print any.
Examples
Input
1
1
Output
1
1
Input
2
10
Output
2
1 0
Input
6
100011
Output
2
100 011
Note
In the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied.
In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal.
In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal.
题意:给出01串,让你分成任意组且每组01个数都不相同
思路:如果本身01串的01个数不同将其本身输出即可,若相同,分成两部分输出,一部分为字符串第一个字符,另一部分剩余部分
 
#include
typedef long long ll; using namespace std; const int maxn=2e5+7; int main() { int n; char str[200]; while(cin>>n){ getchar(); cin>>str; int _0=0,_1=0; for(int i=0;i

 

转载于:https://www.cnblogs.com/Vampire6/p/11142207.html

你可能感兴趣的文章
bzoj 3620 暴力KMP
查看>>
Excel word “由于本机的限制_该操作已被取消_请与管理员联系”的已生效解决办法 (转 )...
查看>>
解压cpio.gz、zip类型文件
查看>>
静态属性和静态方法
查看>>
高效的MySQL分页
查看>>
MooTools 1.2 Beginner's Guide
查看>>
计算储存、交互和语言
查看>>
bzoj2067: [Poi2004]SZN
查看>>
所谓独立环境
查看>>
当代GSM手机的硬件系统分析[zz]
查看>>
对我影响最深的三个老师
查看>>
开源项目托管GitHub
查看>>
Unity学习笔记—— 常用脚本函数
查看>>
.getCellType()的几种类型值
查看>>
linux中启动 java -jar 后台运行程序
查看>>
运行web项目端口占用问题
查看>>
Java Spring-IOC和DI
查看>>
【NOIP1999】【Luogu1015】回文数(高精度,模拟)
查看>>
Linux上安装Python3.5
查看>>
crt安装
查看>>