HDU 3363 Ice-sugar Gourd (贪心)
题意:给你一个串,串中有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 (贪心)的更多相关文章
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- Hdu 3363 Ice-sugar Gourd(对称,圆)
Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5813 Elegant Construction (贪心)
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- HDU 5500 Reorder the Books 贪心
Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
Four Operations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
- HDU 5281 Senior's Gun (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
随机推荐
- thinkphp如果表名有下划线需要用Model
模型命名规范 ThinkPHP 对数据库的表名和模型类的命名遵循一定的规范.首先数据库的表名和字段全部采用小写形式,模型类的命名规则是除去表前缀的数据表名称,并且首字母大写,然后加上模型类的后缀定义. ...
- Java对象和它的内存管理
java中的内存管理分为两个方面: 内存分配:指创建java对象时JVM为该对象在堆空间中所分配的内存空间. 内存回收:指java 对象失去引用,变成垃圾时,JVM的垃圾回收机制自动清理该对象,并回收 ...
- 25_java之Properities集合|对象序列化和反序列化
01Properties集合的特点 * A: Properties集合的特点 * a: Properties类介绍 * Properties 类表示了一个持久的属性集.Properties 可保存在流 ...
- Linux6系统安装
- 版本控制git之二-分支
有人把 Git 的分支模型称为它的`‘必杀技特性’',也正因为这一特性,使得 Git 从众多版本控制系统中脱颖而出. 为何 Git 的分支模型如此出众呢? Git 处理分支的方式可谓是难以置信的轻量, ...
- C# 生成序号不足补0
int Num=13 var code =Num.ToString().PadLeft(4, '0'); code:0013
- BLE 周边设备断开
运行中,突然远程设备断开. TBluetoothLEDevice.IsConnected 为false了. 再次搜索,订阅, BluetoothLE1.SubscribeToCharacteristi ...
- GitHub从注册到使用
GitHub是最流行的代码库,里面存储着丰富的优秀的开源代码,不仅如此,作为一款免费的代码存储利器也是很牛逼,支持各种编程语言,代码显示效果堪称完美,可以随时随地查看自己记录的笔记 GitHub的好处 ...
- Java 单例模式详解(转)
概念: java中单例模式是一种常见的设计模式,单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. ...
- easyui datagrid editor onBeforeEdit事件下使用getEditor和getEditors失效
我在使用onClickRow: function(rowIndex,rowData){ if(editRow!=-1){ ...