HDU 3363 Ice-sugar Gourd

就两种水果,只要各自数目非偶,那就做不到。

都是偶数,那么一定可以两刀解决问题,维持一个总长一半的区间,使其内水果之一,是它总数的一半。问题解决。

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值