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)
Total Submission(s): 1492 Accepted Submission(s): 471

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.
and ‘T’ (means tangerine).
The last test case is followed by a single line containing one zero.
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.
4
HHTT
4
HTHT
4
HHHT
0
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) 收藏的更多相关文章
- 团体程序设计天梯赛L2-021 点赞狂魔 2017-04-18 11:39 154人阅读 评论(0) 收藏
L2-021. 点赞狂魔 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个"点赞"功能,你可以为你 ...
- 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 ...
- MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏
************************************************************ * 标题:MS SQLServer 批量附加数据库 * 说明:请根据下面的注释 ...
- 用IBM WebSphere DataStage进行数据整合: 第 1 部分 分类: H2_ORACLE 2013-08-23 11:20 688人阅读 评论(0) 收藏
转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602zhoudp/ 引言 传统的数据整合方式需要大量的手工 ...
- 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 ...
- 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 ...
- 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 ...
- winfrom 底层类 验证码 分类: C# 2014-12-17 11:18 258人阅读 评论(0) 收藏
效果图: 底层类: /// <summary> /// 生成验证码 /// </summary> /// <param n ...
- 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 ...
随机推荐
- delphi XE3解析JSON数据
测试数据如下: Memo1.text中的数据: { "date":"周二(今天, 实时:12℃)", "dayPictureUrl":&qu ...
- 线性判别分析LDA详解
1 Linear Discriminant Analysis 相较于FLD(Fisher Linear Decriminant),LDA假设:1.样本数据服从正态分布,2.各类得协方差相等.虽然 ...
- post与get的区别
GET请求在URL中传送的参数大多数浏览器限制该长度为2kb的,而POST没有. GET比POST更不安全,因为参数直接暴露在URL上,所以不能用来传递敏感信息. GET参数通过URL传递,POST放 ...
- IDEA kotlin 配置
修改 idea 安装目录 bin 目录 下 idea.properties 文件修改idea.max.intellisense.filesize=50000 避免proto 生成的java文件不被 ...
- linux下字符串的比较方式
A="$1" B="$2" #判断字符串是否相等 if [ "$A" = "$B" ];then echo &qu ...
- redis的五种常见数据类型的常用指令
一.String字符串,key-value 应用场景:string是redis的最基本数据类型,key-value格式,一个key对应一个值的情况下 1.设置key = value:set key ...
- Web标准:八、下拉及多级弹出菜单
Web标准:八.下拉及多级弹出菜单 知识点: 1.带下拉子菜单的导航菜单 2.绝对定位和浮动的区别和运用 3.CSS自适应宽度滑动门菜单 1)带下拉子菜单的导航菜单 带下拉子菜单的就是在一级导航下 ...
- jq闭包
var jy = jQuery.noConflict(); (function($){ //里面跟jq的所有代码 })(jy)
- time,datetime,时间戳 时间格式转换
总结: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) datetime.datetime.now().strftime( ...
- python学习——urlparse模块
urlparse模块: 1.urlparse() 具体程序及结果如下: >>> url = 'http://i.cnblogs.com/EditPosts.aspx?opt=1'&g ...