题意:给你一个串,串中有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. Linux系统启动流程与系统目录

    启动流程 # 1,开机BIOS自检 检查一系列的硬件,最后根据启动顺序启动,是硬盘还是光驱等 # 2,MBR引导 读硬盘0柱面0磁道1扇区的前446字节 1扇区=512字节 MBR=4446字节 四个 ...

  2. iframe有哪些缺点?

    iframe会阻塞主页面的Onload事件:   iframe和主页面共享连接池,而浏览器对相同域的连接有限制,所以会影响页面的并行加载.使用iframe之前需要考虑这两个缺点.如果需要使用ifram ...

  3. OD 实验(六) - 对一个程序的破解

    程序: 双击进行安装,安装过程默认就好了 安装完成 运行程序 输入 User 为 sch01ar,点击 Create 点击 Log In 这里显示为未注册版本 看看未注册版本有哪些功能被限制 这里会显 ...

  4. 解决 service iptables start 无法启动的问题

    解决方式: iptables -F  // 初始化iptables. service iptables save  // 保存 service iptables restart  // 重启

  5. C++ primer plus

    给cout指针,默认打印指针地址,但如果指针的类型的char*,将打印指向的字符串,如果要显示的是字符串的地址,将指针强制转换为另一种类型 char* animal cout << ani ...

  6. 自适应共振理论网络 ART

    引言 自适应共振理论的发源与现状 1976年, 美国 Boston 大学学者 G. A.Carpenter 提出自适应共振理论(Adaptive Res-onance Theory , ART ), ...

  7. .net Reactor之限指定设备使用

    .net Reactor之license限指定设备使用 上一篇(https://www.cnblogs.com/s313139232/p/9908400.html)中记录了.net Reactor对d ...

  8. angularjs之ng-option

    ng-options一般有以下用法: 对于数组: label for value in array select as label for value in array label group by  ...

  9. JBPM4.4学习笔记

    1.JBPM4表说明: JBPM4_DEPLOYMENT 流程定义表 JBPM4_DEPLOYPROP 流程定义属性表 JBPM4_EXECUTION 流程实例表 JBPM4_HIST_ACTINST ...

  10. Synchronized块同步变量的误区

    我们可以通过synchronized块来同步特定的静态或非静态方法.要想实现这种需求必须为这些特性的方法定义一个类变量,然后将这些方法的代码用synchronized块括起来,并将这个类变量作为参数传 ...