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. ORACLE 查询所有用户调度作业

    --查询所有用户调度作业:select * from ALL_SCHEDULER_JOBS; --查询当前用户调度作业:select * from USER_SCHEDULER_JOBS; --查询当 ...

  2. leetcode刷题——排序

    知识点 CS-Notes 备忘-必备算法 题目 冒泡排序 插入排序 归并排序 选择排序 快速排序 希尔排序 堆排序 桶排序 题解 CS-Notes awesome-algorithm

  3. ServletResponse使用方法

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象 request和response对象即然代表请求和响应,那我们要 ...

  4. loj2002 「SDOI2017」序列计数

    水题 #include <iostream> #include <cstring> #include <cstdio> using namespace std; t ...

  5. lfyzoj103 割海成路之日

    问题描述 现在,摆在早苗面前的是一道简单题.只要解决了这道简单题,早苗就可以发动她现人神的能力了: 输出 \[1\ \mathrm{xor}\ 2\ \mathrm{xor} \cdots \math ...

  6. js 格式化 时间插件

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  7. SQL Server数据库和MySQL数据库有什么区别?

    SQL Server数据库和MySQL数据库有什么区别呢?详细很多初入IT行业的朋友对于SQL Server数据库和MySQL数据库经常搞混,认为这两种数据库是同一种,其实不然,今天我们来分析一下这两 ...

  8. 2013年EI收录的中国期刊

    ISSN 刊名 0567-7718 Acta Mechanica Sinica 1006-7191 Acta Metallurgica Sinica (English Letters) 0253-48 ...

  9. cf287D Shifting

    John Doe has found the beautiful permutation formula. Let's take permutation p = p1, p2, ..., pn. Le ...

  10. LightOJ1106 Gone Fishing

    Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...