Ice-sugar Gourd

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 936    Accepted Submission(s): 329

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
 
 

开始用双重for循环,超时了,还是要用一个数组nh[i]来记录到第i个有多少个h

然后从前往后的结果
 
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 123456
int n,cnt_h,cnt_t;
char a[N];
int nh[N]; int main()
{
while(~scanf("%d",&n))
{
getchar();
if(n==)break; cnt_h=;
for(int i=;i<n;i++)
{
scanf("%c",&a[i]);
if(a[i]=='H')cnt_h++;
nh[i]=cnt_h;
}
if(n&)
{
cout<<-<<endl;
continue;
}
if(cnt_h&)
{
cout<<-<<endl;
continue;
}
if(nh[n/-]==cnt_h/)
{
printf("1\n%d\n",n/);
continue;
}
for(int i=;i<n;i++)
{
if(nh[n/+i-]-nh[i-]==cnt_h/)
{
printf("2\n%d %d\n",i,i+n/);
break;
} }
}
return ;
} //freopen("1.txt", "r", stdin);
//freopen("2.txt", "w", stdout);
//**************************************

HDU 3305 Ice-sugar Gourd的更多相关文章

  1. 最短路(数据处理):HDU 5817 Ice Walls

    Have you ever played DOTA? If so, you may know the hero, Invoker. As one of the few intelligence car ...

  2. Hdu 3363 Ice-sugar Gourd(对称,圆)

    Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. HDU 3363 Ice-sugar Gourd (贪心)

    题意:给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. 析:由于只有两个字母,那么只要可以分成两份,那么一定有一段是连续的. 代码如下: #include <c ...

  4. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  5. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  6. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  7. Hdu3363 Ice-sugar Gourd 2017-01-16 11:39 43人阅读 评论(0) 收藏

    Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. HDU 2134 Cuts the cake

    http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...

  9. ZeroC Ice启用SSL通讯的配置

    Zeroc ICE ( Internet Communications Engine )中间件号称标准统一,开源,跨平台,跨语言,分布式,安全,服务透明,负载均衡,面向对象,性能优越,防火墙穿透,通讯 ...

随机推荐

  1. PHP获得网页源码

    获取网页源代码: <?php $lines = file('http://www.hoverreader.com/'); foreach ($lines as $line_num => $ ...

  2. Java面试之基础题---对象Object

    参数传递:Java支持两种数据类型:基本数据类型和引用数据类型. 原始数据类型是一个简单的数据结构,它只有一个与之相关的值.引用数据类型是一个复杂的数据结构,它表示一个对象.原始数据类型的变量将该值直 ...

  3. ubuntu 终端查看图片(eog)

    远程登陆服务器的话,是没有办法直接查看图片的,这时我们需要进入图片所在目录,然后通过终端命令查看图片. 想要查看图片,需要通过ssh -X登陆,然后在终端输入命令: eog 图片名

  4. TOJ 4244: Sum

    4244: Sum   Time Limit(Common/Java):3000MS/9000MS     Memory Limit:65536KByteTotal Submit: 63       ...

  5. “玲珑杯”ACM比赛 Round #13 B -- 我也不是B,倍增+二分!

    B  我也不是B   这个题做了一下午,比赛两个小时还是没做出来,比完赛才知道要用一个倍增算法确定区间,然后再二分右端点.   题意:定义一个序列的混乱度为累加和:b[i]*v[i],b[i]为这个序 ...

  6. 信息安全试验-DES加密!

    信息安全试验二--DES加密算法 本渣表示没有理解原理,照着书上敲了一发,运行无误! 吐槽:手动S盒简直丧心病狂,扩展置换表全是手动输入,加密原理还是很好理解,两次异或,先混淆. 此代码数据由老师给出 ...

  7. 【Luogu】P1462通往奥格瑞玛的道路(二分答案+SPFA)

    题目链接 导致我WA十几遍的原因居然是最大值不够大……以后再也不相信memset(dis,127/3,sizeof(dis))了. 此题先将花费排序,然后二分最大花费,spfa判断解是否可行.spfa ...

  8. [BZOJ1574] [Usaco2009 Jan]地震损坏Damage(贪心 + dfs)

    传送门 告诉你一些点不能到达1,由于是双向边,也就是1不能到达那些点 那么从1开始dfs,如果当前点能到达不能到达的点,那么当前点就是损坏的. #include <cstdio> #inc ...

  9. 刷题总结——bzoj1725(状压dp)

    题目: 题目描述 Farmer John 新买了一块长方形的牧场,这块牧场被划分成 N 行 M 列(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地. FJ  ...

  10. HashMap构造函数有哪些

    hashMap有4个构造函数: public HashMap(int initialCapacity, float loadFactor) public HashMap(int initialCapa ...