Ice-sugar Gourd

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1492    Accepted Submission(s): 471

Problem Description
Ice-sugar gourd, “bing tang hu lu”, is a popular snack in Beijing of China. It is made of some fruits threaded by a stick. The complicated feeling will be like a both sour and sweet ice when you taste it. You are making your mouth water, aren’t you?



I have made a huge ice-sugar gourd by two kinds of fruit, hawthorn and tangerine, in no particular order. Since I want to share it with two of my friends, Felicia and his girl friend, I need to get an equal cut of the hawthorns and tangerines. How many times
will I have to cut the stick so that each of my friends gets half the hawthorns and half the tangerines? Please notice that you can only cut the stick between two adjacent fruits, that you cannot cut a fruit in half as this fruit would be no good to eat.
 
Input
The input consists of multiply test cases. The first line of each test case contains an integer, n(1 <= n <= 100000), indicating the number of the fruits on the stick. The next line consists of a string with length n, which contains only ‘H’ (means hawthorn)
and ‘T’ (means tangerine).

The last test case is followed by a single line containing one zero.
 
Output
Output the minimum number of times that you need to cut the stick or “-1” if you cannot get an equal cut. If there is a solution, please output that cuts on the next line, separated by one space. If you cut the stick after the i-th (indexed from 1) fruit, then
you should output number i to indicate this cut. If there are more than one solution, please take the minimum number of the leftist cut. If there is still a tie, then take the second, and so on.
 
Sample Input
4
HHTT
4
HTHT
4
HHHT
0
 
Sample Output
2
1 3
1
2
-1
 

____________________________________________________________________________________

解题大意:
给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半。
解题思路:
把串想象成一个环,只要满足H跟T都为偶数个,那么就可以做一条过圆心的直线把H跟T平分掉,
过直线,只要考虑平分H或者T中的一个就可以了,因为直线本来就把环平分,而此时平分了H或者T,
那么剩下的那个也是平分掉的。
暴力枚举即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set> using namespace std; char s[100005]; int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
scanf("%s",s);
int H=0,T=0;
for(int i=0;i<n;i++)
{
if(s[i]=='H')
H++;
else
T++;
}
if(H%2||T%2)
{
printf("-1\n");
continue;
}
int h=0,t=0;
for(int i=0;i<n/2;i++)
{
if(s[i]=='H')
h++;
else
t++;
}
if(h==H/2&&t==T/2)
{
printf("1\n%d\n",n/2);
continue;
}
int p=0;
for(int i=n/2;i<n;i++,p++)
{
if(t==T/2&&h==H/2)
{
printf("2\n%d %d\n",p,i);
break;
}
if(s[p]=='H')
h--;
else
t--;
if(s[i]=='H')
h++;
else
t++;
}
}
return 0;
}

Hdu3363 Ice-sugar Gourd 2017-01-16 11:39 43人阅读 评论(0) 收藏的更多相关文章

  1. 团体程序设计天梯赛L2-021 点赞狂魔 2017-04-18 11:39 154人阅读 评论(0) 收藏

    L2-021. 点赞狂魔 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个"点赞"功能,你可以为你 ...

  2. Hdu2204 Eddy's爱好 2017-06-27 16:11 43人阅读 评论(0) 收藏

    Eddy's爱好 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  3. MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏

    ************************************************************ * 标题:MS SQLServer 批量附加数据库 * 说明:请根据下面的注释 ...

  4. 用IBM WebSphere DataStage进行数据整合: 第 1 部分 分类: H2_ORACLE 2013-08-23 11:20 688人阅读 评论(0) 收藏

    转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602zhoudp/ 引言 传统的数据整合方式需要大量的手工 ...

  5. hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏

    use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...

  6. Curling 2.0 分类: 搜索 2015-08-09 11:14 3人阅读 评论(0) 收藏

    Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14289 Accepted: 5962 Descript ...

  7. Fibonacci Again 分类: HDU 2015-06-26 11:05 13人阅读 评论(0) 收藏

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  8. winfrom 底层类 验证码 分类: C# 2014-12-17 11:18 258人阅读 评论(0) 收藏

    效果图: 底层类: /// <summary>         /// 生成验证码         /// </summary>         /// <param n ...

  9. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

随机推荐

  1. Haskell语言学习笔记(38)Lens(1)

    Lens Lens是一个接近语言级别的库,使用它可以方便的读取,设置,修改一个大的数据结构中某一部分的值. view, over, set Prelude> :m +Control.Lens P ...

  2. go递归函数如何传递数组切片slice

    数组切片slice这个东西看起来很美好,真正用起来会发现有诸多的不爽. 第一,数组.数组切片混淆不清,使用方式完全一样,有时候一些特性又完全不一样,搞不清原理很容易误使用. 第二,数组切片的appen ...

  3. Ansible Playbook 循环

    Standard Loops 为了节省一些打字,重复的任务可以写成如下: - name: add several users user: name: "{{ item }}" st ...

  4. Hive—学习笔记(一)

    主要内容: 1.Hive的基本工能机制和概念 2.hive的安装和基本使用 3.HQL 4.hive的脚本化运行使用方式 5.hive的基本语法--建表语法 6.hive的基本语法--内部表和外部表. ...

  5. 使用sizemask来确保索引不越界

    [使用sizemask来确保索引不越界] 在redis的字典实现中,有一个sizemask字段. 此字段的作用是当使用下标访问数据时,确保下标不越界. 如当前size为8时,sizemask为7(0x ...

  6. mogodb查询

    Find: {$and: [ {"MethodName":"CommLogin"} ,{"CreateTime":{$gte:"2 ...

  7. Memtester——Linux内存测试工具

    一.Memtester简单介绍 Memtester主要是捕获内存错误和一直处于很高或者很低的坏位, 其测试的主要项目有随机值,异或比较,减法,乘法,除法,与或运算等等. 通过给定测试内存的大小和次数, ...

  8. keras—多层感知器MLP—IMDb情感分析

    import urllib.request import os import tarfile from keras.datasets import imdb from keras.preprocess ...

  9. 关于"undefined reference"错误

    这个错误换句话说: 链接的时候找不到实现的文件(谨记从这个入手!). 可能导致的原因有: 1. 没有链接库文件,包括静态库或动态库. 2. 链接文件的顺序问题,先后依赖问题,把被依赖的放后面. 3. ...

  10. OC 线程操作3 - NSOperation

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...