CF1189A-Keanu Reeves(基努·里维斯)(idea+字符串)

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.

玩完黑客帝国传奇三部曲之后,基努·里维斯(主角演员)开始怀疑人生:我们是不是真的活在VR当中?为了探究这是不是真的,他得去解决如下的问题。

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, 0000are good, while 01, 1001, and 111000 are not good.

我们认为一个只含有0和1,并且0和1数目不同的一个字符串是个好字符串。比如说,1,101,0000都是好字符串,但是01,1001,和111000都不是好字符串。

We are given a string ss of length nn consisting of only zeroes and ones. We need to cut ss into minimal possible number of substrings s1,s2,…,sks1,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,…,sks1,s2,…,sk such that their concatenation (joining) equals ss, i.e. s1+s2+⋯+sk=ss1+s2+⋯+sk=s.

我们给定了一个字符串s,长度为n,这里边仅仅包含0和1。我们得用尽量小的分段数把原字符串分成“好的”子字符串。更正式的说,我们得去找一个以最小数目切分字符串,并且各个子字符串最终得拼成原字符串(就是只能直接分段,不能逐项挑)。

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 33 strings are good.

比如说,切110010为110和010或者切成11和0010都是合理的。 但是没法把110010切成更小部分(一段就是不切),因为110010本身不符合题意。也没法把它切成不好的字符串。

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 nn (1≤n≤1001≤n≤100) — the length of the string ss.

第一行输入包含一个整数

The second line contains the string ss of length nn consisting only from zeros and ones.

第二行包含一个01字符串

Output

In the first line, output a single integer kk (1≤k1≤k) — a minimal number of strings you have cut ss into.

In the second line, output kk strings s1,s2,…,sks1,s2,…,sk separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to ss and all of them have to be good. 

If there are multiple answers, print any.

Examples

input

Copy

1
1

output

Copy

1
1

input

Copy

2
10

output

Copy

2
1 0

input

Copy

6
100011

output

Copy

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.

这个题的核心就是一个IDEA:对于相等的01个数总是可以通过移出任意一个0或1使得刚才的稳定对数被打破。

那么,这个题只需两个思路方向:

  1. 已输入的字符串01不能一一匹配,直接就是答案
  2. 输入的字符串可以一一匹配,拆出最后一个数即可满足题给条件。这时段数总是2。

 思路简述如上。

//#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 33;
inline ll lldcin()
{
	ll tmp = 0, si = 1;
	char c;
	c = getchar();
	while (c > '9' || c < '0')
	{
		if (c == '-')
			si = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		tmp = tmp * 10 + c - '0';
		c = getchar();
	}
	return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
string tmp;
int DETERMINATION()
{
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	cin >> tmp;
	ll cnt0 = 0, cnt1 = 0;
	for (char i : tmp)//判断0与1的个数
	{
		if (i == '0')
			cnt0++;
		else
			cnt1++;
	}
	if (cnt1 != cnt0)//情况1
	{
		cout << 1 << endl << tmp << endl;
	}
	else//情况2
	{
		cout << 2 << endl;
		for (int i = 0; i < n - 1; i++)
			cout << tmp[i];
		cout << " " << tmp[n - 1] << endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用C++中的stoi函数将字符串转换为整数。例如: ```cpp #include <iostream> #include <string> int main() { std::string str = "123"; int num = std::stoi(str); std::cout << "The string \"" << str << "\" is converted to integer " << num << std::endl; return 0; } ``` 输出: ``` The string "123" is converted to integer 123 ``` ### 回答2: 字符串转换为整数是计算机编程中的一个常见需求。在许多编程语言中,都提供了相应的方法或函数来完成这种转换。 在Python中,可以使用int()函数将字符串转换为整数。例如,如果有一个字符串变量str_num,其值为"123",可以使用int()函数将其转换为整数类型: ```python str_num = "123" int_num = int(str_num) ``` 在这个例子中,变量int_num的值将为整数123。需要注意的是,字符串必须只包含数字字符,否则会引发ValueError异常。 在Java中,可以使用Integer类的parseInt()方法将字符串转换为整数。例如,如果有一个字符串变量strNum,其值为"456",可以使用parseInt()方法将其转换为整数类型: ```java String strNum = "456"; int intNum = Integer.parseInt(strNum); ``` 在这个例子中,变量intNum的值将为整数456。与Python类似,字符串必须只包含数字字符,否则会引发NumberFormatException异常。 无论是使用Python还是Java,字符串转换为整数是一项常用的操作,可以帮助我们处理字符型的数字数据,方便进行数值计算和处理。 ### 回答3: 将字符串转换为整数,可以使用int()函数来实现。int()函数接受一个字符串参数,并将其转换为整数类型。 例如,假设有一个字符串变量str_val = "123",需要将其转换为整数类型。可以使用int()函数进行转换,代码如下: ```python str_val = "123" int_val = int(str_val) print(int_val) ``` 运行结果为: ``` 123 ``` 同样地,如果字符串不能被转换为有效的整数,将会引发ValueError异常。例如,将字符串"abc"转换为整数类型会发生错误,代码如下: ```python str_val = "abc" int_val = int(str_val) # 这里会触发异常 print(int_val) ``` 运行结果为: ``` Traceback (most recent call last): File "<stdin>", line 2, in <module> ValueError: invalid literal for int() with base 10: 'abc' ``` 因此,在使用int()函数进行字符串转换为整数时,需要确保字符串的内容可以被正确地解析为整数类型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值