HDU 3305 Ice-sugar Gourd
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
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 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.
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.
HHTT
4
HTHT
4
HHHT
0
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的更多相关文章
- 最短路(数据处理):HDU 5817 Ice Walls
Have you ever played DOTA? If so, you may know the hero, Invoker. As one of the few intelligence car ...
- Hdu 3363 Ice-sugar Gourd(对称,圆)
Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 3363 Ice-sugar Gourd (贪心)
题意:给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. 析:由于只有两个字母,那么只要可以分成两份,那么一定有一段是连续的. 代码如下: #include <c ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- 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) ...
- HDU 2134 Cuts the cake
http://acm.hdu.edu.cn/showproblem.php?pid=2134 Problem Description Ice cream took a bronze medal in ...
- ZeroC Ice启用SSL通讯的配置
Zeroc ICE ( Internet Communications Engine )中间件号称标准统一,开源,跨平台,跨语言,分布式,安全,服务透明,负载均衡,面向对象,性能优越,防火墙穿透,通讯 ...
随机推荐
- VC调试入门
概述调试是一个程序员最基本的技能,其重要性甚至超过学习一门语言.不会调试的程序员就意味着他即使会一门语言,却不能编制出任何好的软件.这里我简要的根据自己的经验列出调试中比较常用的技巧,希望对大家有用. ...
- kendo Grid 列添加自定义模板
columns: [ {field: "行为",template: "<a href='#= 行为#'>#= 行为#</a>"}, {f ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- [uiautomator篇]recent
def Recent(self): d = Device('9410519008004c22098b') displayWidth = int(d.info.get("displayWidt ...
- nginx报错502
http请求流程:一般情况下,提交动态请求的时候,nginx会直接把 请求转交给php-fpm,而php-fpm再分配php-cgi进程来处理相关的请求,之后再依次返回,最后由nginx把结果反馈给客 ...
- BZOJ3996 [TJOI2015]线性代数 【最小割】
题目 给出一个NN的矩阵B和一个1N的矩阵C.求出一个1*N的01矩阵A.使得 D=(AB-C)A^T最大.其中A^T为A的转置.输出D 输入格式 第一行输入一个整数N,接下来N行输入B矩阵,第i行第 ...
- tomact和eclipse的关联
tomact和eclipse的关联有很多文档,这里说下下面的问题: 问题: tomact安装成功,点击startup.sh能正常访问,通过eclipse启动后,不能打开8080页面 解决: l 重 ...
- 【DFS序+线段树区间更新区间求最值】HDU 5692 Snacks
http://acm.hdu.edu.cn/showproblem.php?pid=5692 [思路] 每更新一个点,子树的所有结点都要更新,所以是区间更新 每查询一个点,子树的所有结点都要查询,所以 ...
- db2数据备份与恢复
备份:先关掉所有tomcat运行:db2cmd db2Stop force db2Start DB2 FORCE APPLICATIONS ALL DB2 BACKUP DATABASE histes ...
- itext A4纸张横向创建PDF
import java.awt.Color;import java.io.FileOutputStream;import java.io.IOException; import com.lowagie ...