就两种水果,只要各自数目非偶,那就做不到。
都是偶数,那么一定可以两刀解决问题,维持一个总长一半的区间,使其内水果之一,是它总数的一半。问题解决。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn=100010;
char S[maxn];
int HS[maxn];
int main() {
int n;
while (~scanf ("%d",&n) &&n) {
scanf ("%s",S);
int h=0;
for (int i=0; i<n; ++i) {
if (S[i]=='H') {++h;}
HS[i]=h;
}
if (n%2!=0||h%2!=0) {
printf ("-1\n"); continue;
}
if (HS[n/2-1]==h/2) {
printf ("1\n%d\n",n/2); continue;
}
for (int i=1; i<n/2; ++i) {
if ( (HS[i+n/2-1]-HS[i-1]) ==h/2) {
printf ("2\n%d %d\n",i,i+n/2);
break;
}//only need cut two times,keep the n/2 space
}
}
return 0;
}