题意:给你一个串,串中有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. MongoDB day01

    MongoDB芒果数据库 数据存储阶段 文件管理阶段(.txt .doc .xlc) 优点:数据可以长期保存:数据有一定格式化规范:可以大量存储:使用简单方便 缺点:数据一致性差:用户查找修改不方便: ...

  2. url携带的参数获取并处理demo

    url demo: http://servername/webname/pagename.csp?paramName=paramValue&paramName2=paramName2& ...

  3. WP8 MVVM设计模式

    类似了Android里边的MVC模式, Windows Phone 有自己的Model-View-ViewModel模式,这种模式的作用就是为了Data和UI分离开来. 如果你英文较好的话,你可以不再 ...

  4. zabbix 报警方式之 微信公众号报警(5)

    一.条件 首先你得有一个微信公众号,并且是可以有发送消息的接口.然后你得有个脚本去调用微信的api. 这里感谢一下微信.使我们运维人员的报警方式多了一种... (同事们不要怪我哈.) 之后可以参考下z ...

  5. 数据库DRDS中间件介绍

    DRDS/TDDL alibaba. Distributed Relational Database Service. 阿里分布式数据库DRDS的前身是淘宝分布式数据库层TDDL,大概在2012年的时 ...

  6. 在ubuntu中添加新硬盘

    在ubuntu中添加新硬盘 转载于 http://www.cnblogs.com/unipower/archive/2009/03/08/1406230.html  前言 安装新硬盘这种事情并不会经常 ...

  7. [ Python ] Flask 基于 Web开发 大型程序的结构实例解析

    作为一个编程入门新手,Flask是我接触到的第一个Web框架.想要深入学习,就从<FlaskWeb开发:基于Python的Web应用开发实战>这本书入手,本书由于是翻译过来的中文版,理解起 ...

  8. sql之分区域分段统计

    sql之分区域分段统计 需求:在一个表中,有两列分别标记行政区划代码和家庭成员人数,需要得到不同乡镇的家庭成员人数在1-2人,3-4人,5-6人,6人以上的家庭数的表格 思路: 用case when对 ...

  9. python学习——练习题(12)

    """ 题目:判断101-200之间有多少个素数,并输出所有素数. 质数(prime number)又称素数,有无限个. 质数定义为在大于1的自然数中,除了1和它本身以外 ...

  10. mongodb 的操作

    查找 db.collection的名字.find({"group":"kkkk","key":{$regex:/.*one.*/i}}); ...