COJ 0036 数数happy有多少个?
数数happy有多少个? |
难度级别:B; 运行时间限制:1000ms; 运行空间限制:51200KB; 代码长度限制:2000000B |
试题描述
|
图图是个爱动脑子、观察能力很强的好学生。近期他正学英语单词,练字时无意识地写了一串小写英文字母,他发现这串字母中包含了很多个happy,他决定计算一下到底有多少个happy。规则是这样的:在该字符串提取任意位置的字符组成新的单词串,不改变其在原字符串中的相对顺序,请你编写程序帮助图图统计出新的单词串种最多有多少个happy。 |
输入
|
输入只有一行,含有一个字符串。字符串由小写字母a – z组成。此字符串长度不超过10000。
|
输出
|
一个非复整数。表示按照题目描述的规则最多能够组成单词happy的个数。
|
输入示例
|
hahappyppy
|
输出示例
|
2
|
题解:数据好水看我hack他们!我自认为我的写法挺好的了。。。(雾
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
using namespace std;
inline int read(){
int x=,sig=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')sig=-;ch=getchar();}
while(isdigit(ch))x=*x+ch-'',ch=getchar();
return x*=sig;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
char ch;int cnt[];
void init(){
for(ch=getchar();isalpha(ch);ch=getchar()){
if(ch=='h') cnt[]++;
if(ch=='a') if(cnt[]<cnt[]) cnt[]++;
if(ch=='p') if(cnt[]<(cnt[]<<)) cnt[]++;
if(ch=='y') if(cnt[]<(cnt[]>>)) cnt[]++;
}
}
void work(){
return;
}
void print(){
write(cnt[]);
return;
}
int main(){init();work();print();return ;}
原来愚蠢的code:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
using namespace std;
const int maxn=+;
int s[][maxn],tot[],cnt[];
int check(int d,int t){
for(;cnt[d]<tot[d];cnt[d]++){
if(s[d][cnt[d]]>t) return s[d][cnt[d]];
} return -;
}
inline int read(){
int x=,sig=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')sig=-;ch=getchar();}
while(isdigit(ch))x=*x+ch-'',ch=getchar();
return x*=sig;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
char ch;
void init(){
int t=;
for(ch=getchar();isalpha(ch);ch=getchar()){
if(ch=='h') s[][tot[]++]=t++;
else if(ch=='a') s[][tot[]++]=t++;
else if(ch=='p') s[][tot[]++]=t++;
else s[][tot[]++]=t++;
}
return;
}
int ans;
void work(){
for(int i=;i<tot[];i++){
int t=s[][i];
if((t=check(,t))<)break;
if((t=check(,t))<)break;
if((t=check(,t))<)break;
if((t=check(,t))<)break;
ans++;
}
return;
}
void print(){
write(ans);
return;
}
int main(){init();work();print();return ;}
COJ 0036 数数happy有多少个?的更多相关文章
- ACM_数数有多少(第二类Stirling数-递推dp)
数数有多少 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小财最近新开了一家公司,招了n个员工,但是因为资金问题,办公楼只有m间 ...
- BZOJ 3530: [Sdoi2014]数数 [AC自动机 数位DP]
3530: [Sdoi2014]数数 题意:\(\le N\)的不含模式串的数字有多少个,\(n=|N| \le 1200\) 考虑数位DP 对于长度\(\le n\)的,普通套路DP\(g[i][j ...
- [HZOI 2016]我们爱数数
[HZOI 2016]我们爱数数 题目大意: 一张圆桌,每个位置按顺时针从\(1\)到\(n\)编号.有\(n\)个人,编号从\(1\)到\(n\).如果编号为\(i\)的人坐到了编号为\(i\)的位 ...
- P4844 LJJ爱数数 数论
思路: 化简后得到(a+b)c=ab,设g=(a,b),A=a/g,B=b/g,则g(A+B)c=ABg^2,即(A+B)c=ABg 由题目已知条件:(a,b,c)=1,即(g,c)=1,g|(A+B ...
- 8.22 NOIP模拟测试29(B) 爬山+学数数+七十和十七
T1 爬山 二分最高高度,$O(1)$判断是否可行. #include<iostream> #include<cstdio> #define ll long long usin ...
- JZOJ3492数数&&GDOI2018超级异或绵羊——位&&类欧几里得
JZOJ3492 数数(count) 我们知道,一个等差数列可以用三个数A,B,N表示成如下形式: B+A,B+2A,B+3A⋯B+NA ztxz16想知道对于一个给定的等差数列,把其中每一项用二进 ...
- wmz的数数(数状数组)
wmz的数数(数状数组) 题目描述 \(wmz\)从小就显现出了过人的天赋,他出生的第三天就证明了哥德巴赫猜想,第五天就证明了质能方程,出生一星期之后,他觉得\(P\)是否等于\(NP\)这个问题比前 ...
- NOIP模拟测试29「爬山·学数数·七十和十七」
爬山题解不想写了 学数数 离散化然后找到以每一个值为最大值的连续子段有多少个,然后开个桶维护 那么怎么找以每一个值为最大值的连续子段个数 方法1(我的极笨的方法) 考试时我的丑陋思路, 定义极左值为左 ...
- 【BZOJ】【3530】【SDOI2014】数数
AC自动机/数位DP orz zyf 好题啊= =同时加深了我对AC自动机(这个应该可以叫Trie图了吧……出边补全!)和数位DP的理解……不过不能自己写出来还真是弱…… /************* ...
随机推荐
- acm - cry for no one
再一次回到实验室,距离上次已经四个多月了.诸多业障,三界无安,犹如火灾,众若充满,甚可怖畏,常有生老病死 忧患,如是等火,炽然不息.<成实论>云:“万法刹那生,万法刹那灭,转转相续也”.又 ...
- awk使用入门
1.基本用法 awk '{pattern + action}' {filenames} pattern 表示 AWK 在数据中查找的内容 action 是在找到匹配内容时所执行的一系列命令. patt ...
- SKPhysicsWorld类
继承自 NSObject 符合 NSCodingNSObject(NSObject) 框架 /System/Library/Frameworks/SpriteKit.framework 可用性 可用 ...
- unity3d优化IOS
1. using UnityEngine; class GarbageCollectManager : MonoBehaviour { public int frameFreq = 30; ...
- python 下的数据结构与算法---6:6大排序算法
顶先最后推荐:哈哈,意思是放到顶部强调其重要性,但是应该我总结的六种算法看完了后再看的一篇醍醐灌顶的文章 一:冒泡排序(Bubble Sort) 原理:假设有n个数,第一轮时:从第一个元素开始,与相邻 ...
- java的final变量理解
java的final变量理解 final基本类型是数值不能改变 final对象是引用不能改变,对象其自身是可以被修改的.
- Android开发中在一个Activity中关闭另一个Activity
比如有ActivityA, ActivityB,在ActivityB中关闭ActivityA 解决方案: 1. 在 ActivityA 里面设置一个静态的变量instance,初始化为this在 Ac ...
- 制作ado开发辅助工具类SqlHelper
public static class SqlHelper { //通过配置文件获取连接字符创 private static readonly string constr = Configuratio ...
- Cer Crt Pem Pfx 证书格式转换
1.从pfx格式的证书提取出密钥和证书set OPENSSL_CONF=openssl.cnfopenssl pkcs12 -in my.pfx -nodes -out server.pemopens ...
- XML Schema (2)
定义元素 <!-- 1.定义元素book --> <element name="book"></element> <!-- 2.定义元素包 ...