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> ...
随机推荐
- Django-MTV模型
MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Template(模版):负责如何把页面展示给用户 View(视图):负责业务逻辑,并在适当的时候 ...
- 设计模式—三种工厂模式(JAVA)
一:简单工厂: 有一个实际工厂,这个工厂只能造一类的产品,这一类产品就是一个产品接口,会有多个具体产品实现这个接口,例 如,一个手机厂,生产苹果手机,三星手机: 缺点:在工厂类中集中了所有实例的创建逻 ...
- 全连接BP神经网络
前馈神经网络 前馈神经网络(feedforward neural network)是最朴素的神经网络,通常我们所说的前馈神经网络有两种,一种叫反向传播网络(Back propagation Netwo ...
- 安装FFmpeg3.0.9
//静态版的 FFmpeg Static Builds release: 3.3.3 https://www.johnvansickle.com/ffmpeg/ ffmpeg-release-64 ...
- mysql数据安全一之数据恢复案例
mysql数据安全一之数据恢复案例 --chenjianwen 应用场景:适宜开启binlog 日志功能,定时备份并使用--master-data参数备份,在某个时间点丢失数据,用于数据恢复 开篇总结 ...
- JSR-303 结合spring 校验
使用注解 一.准备校验时使用的JAR validation-api-1.0.0.GA.jar:JDK的接口: hibernate-validator-4.2.0.Final.jar是对上述接口的实现: ...
- 12_java之构造方法|this|super
01构造方法引入 * A:构造方法的引入 在开发中经常需要在创建对象的同时明确对象的属性值,比如员工入职公司就要明确他的姓名.年龄等属性信息. 那么,创建对象就要明确属性值,那怎么解决呢?也就是在创建 ...
- ArcGIS 二次开发增加工具栏按钮时,给按钮图标设置失败
在类的构造函数中通过下面的代码获得的bitmap为null: string bitmapResourceName = GetType().Name + ".bmp"; base.m ...
- leetcode445
/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNo ...
- python开源项目Scrapy抓取文件乱码解决
scrapy进行页面抓去的时候,保存的文件出现乱码,经过分析是编码的原因,只需要把编码转换为utf-8即可,代码片段 ...... import chardet ...... cont ...