题意:给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半。

析:由于只有两个字母,那么只要可以分成两份,那么一定有一段是连续的。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
char s[maxn]; int main(){
int n, x;
while(scanf("%d", &n) == 1 && n){
scanf("%s", s);
int h = 0, t = 0;
for(int i = 0; i < n; ++i){
if(s[i] == 'H') ++h;
else ++t;
}
if((t&1) || (h&1)){
printf("-1\n");
continue;
}
t /= 2;
h /= 2; int ss = 0, e = 0;
int cnth = 0, cntt = 0;
while(ss < n){
bool ok = false;
while(e < n && cnth + cntt < n/2){
s[e] == 'H' ? ++cnth : ++cntt;
++e;
if(cnth == h && cntt == t){
ok = true;
if(ss == 0) printf("1\n");
else printf("2\n");
if(ss == 0) printf("%d\n", n/2);
else printf("%d %d\n", ss, ss+n/2);
} }
if(ok) break;
s[ss] == 'H' ? --cnth : --cntt;
++ss;
}
}
return 0;
}

HDU 3363 Ice-sugar Gourd (贪心)的更多相关文章

  1. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  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 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  4. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  5. HDU 5500 Reorder the Books 贪心

    Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

    Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. HDU 3697 Selecting courses(贪心)

    题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...

  8. HDU 5281 Senior's Gun (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...

  9. hdu 1257 && hdu 1789(简单DP或贪心)

    第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...

随机推荐

  1. 关于git rebase的相关讲解

    http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin" ...

  2. 使用poi读写Excel------demo

    package com.js.ai.modules.pointwall.interfac; import java.io.FileInputStream; import java.io.FileOut ...

  3. cocos2d中的坐标系统

    cocos2d中Layer的默认锚点是left.buttom sprite的锚点设置 setAnchorPoint(cc.p(0.5,0.5)); 默认锚点:中心 setAnchorPoint(cc. ...

  4. Docker 存储之卷(Volume)

      理解Docker(8):Docker 存储之卷(Volume) (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 Linux namespa ...

  5. Flask之视图(二)

    2.2 扩展 上下文:相当于一个容器,保存了Flask程序运行过程中的一些信息. Flask中有两种上下文,请求上下文和应用上下文. 请求上下文(request context) request和se ...

  6. 你所不知道的javascript数组特性

    工作中,我们经常使用js的数组,但是,下面的东西你见过吗? 1,文本下标: var a=[]; a[-1]=1; 你想过数组的下标为负数的情况吗?我们对数组的下标规定从0开始.但是上面那么写也还是可以 ...

  7. Oracle11gr2_ADG管理之在备库上模拟failover的过程实战

    技术建议和方案. 要求failover后不重建备库,并能够把failover的数据库重新切换回备库 主库为newtest,备库为snewtest 备库上已经开启了闪回 得到一个参考的SCN SQL&g ...

  8. Linux虚机密码破解

    1 重启机器,在机器读秒时按回车键 2 选择要启动的操作系统按 e 3 选择kernel所在行按 e 4 末尾输入空格  single 5 敲回车 在按 b 系统将进入单用户模式 然后 可以 通过 p ...

  9. excel表格的应用之简单的数据可视化

    上面的为我们需要的手长与身高的数据 上面的是我们的数据可视化之后的点状图 我们需要先选中我们需要的数据表 然后点击我们插入中的推荐图表的选项 点开后会弹出这个界面 然后我们只需要选择char进行插入就 ...

  10. BAT脚本编写教程

    windows批处理 (cmd/bat) 编程详解 开始之前先简单说明下cmd文件和bat文件的区别:在本质上两者没有区别,都是简单的文本编码方式,都可以用记事本创建.编辑和查看.两者所用的命令行代码 ...