数数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有多少个?的更多相关文章

  1. ACM_数数有多少(第二类Stirling数-递推dp)

    数数有多少 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小财最近新开了一家公司,招了n个员工,但是因为资金问题,办公楼只有m间 ...

  2. BZOJ 3530: [Sdoi2014]数数 [AC自动机 数位DP]

    3530: [Sdoi2014]数数 题意:\(\le N\)的不含模式串的数字有多少个,\(n=|N| \le 1200\) 考虑数位DP 对于长度\(\le n\)的,普通套路DP\(g[i][j ...

  3. [HZOI 2016]我们爱数数

    [HZOI 2016]我们爱数数 题目大意: 一张圆桌,每个位置按顺时针从\(1\)到\(n\)编号.有\(n\)个人,编号从\(1\)到\(n\).如果编号为\(i\)的人坐到了编号为\(i\)的位 ...

  4. 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 ...

  5. 8.22 NOIP模拟测试29(B) 爬山+学数数+七十和十七

    T1 爬山 二分最高高度,$O(1)$判断是否可行. #include<iostream> #include<cstdio> #define ll long long usin ...

  6. JZOJ3492数数&&GDOI2018超级异或绵羊——位&&类欧几里得

    JZOJ3492 数数(count) 我们知道,一个等差数列可以用三个数A,B,N表示成如下形式:  B+A,B+2A,B+3A⋯B+NA ztxz16想知道对于一个给定的等差数列,把其中每一项用二进 ...

  7. wmz的数数(数状数组)

    wmz的数数(数状数组) 题目描述 \(wmz\)从小就显现出了过人的天赋,他出生的第三天就证明了哥德巴赫猜想,第五天就证明了质能方程,出生一星期之后,他觉得\(P\)是否等于\(NP\)这个问题比前 ...

  8. NOIP模拟测试29「爬山·学数数·七十和十七」

    爬山题解不想写了 学数数 离散化然后找到以每一个值为最大值的连续子段有多少个,然后开个桶维护 那么怎么找以每一个值为最大值的连续子段个数 方法1(我的极笨的方法) 考试时我的丑陋思路, 定义极左值为左 ...

  9. 【BZOJ】【3530】【SDOI2014】数数

    AC自动机/数位DP orz zyf 好题啊= =同时加深了我对AC自动机(这个应该可以叫Trie图了吧……出边补全!)和数位DP的理解……不过不能自己写出来还真是弱…… /************* ...

随机推荐

  1. Oracle 数据库基本操作——表操作:查询

    目录: 1.基本查询 2.多表查询 3.多行查询 4.集合查询 2.连接 3.嵌套查询 1.基本查询 语法: select column|others{,columnName|others} from ...

  2. Project Euler:Problem 47 Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The ...

  3. ubuntu eclipse CDT 问题

    问题一:ubuntu eclipse c++ launch failed binary not found 解决:建完项目后 查看在项目中是不是有debug目录,说明没有编译.仅仅是须要做例如以下操作 ...

  4. Linux安装应用程序对程序文件owner/group和执行程序帐号设置的规范做法

    本文原文链接:http://blog.csdn.net/bluishglc/article/details/24384189 转载请注明出外! 本文面向的是在server环境下对已编译.自解压应用程序 ...

  5. unity3d触屏操作对象运动

    using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...

  6. Easyui弹出窗体在iframe的父级页面显示

    今天做EasyUI学习的预到了一个这样的问题:通过iframe加载的一个页面在调用$.messager.alert();这个方法后只能在iframe中显示alert效果而不是在全局的页面上显示这并不我 ...

  7. 配置NFS服务器

    一.配置NFS服务器 1.安装软件包 [root@wjb10000 ~]# yum -y install nfs-utils.x86_64 2.修改配置文件[root@wjb10000 ~]# vim ...

  8. linux批量执行工具omnitty使用方法

    一.omnitty概述 在生产环境中,可能会有多台linux主机.运维人员可能会对多台主机进行同样的操作,例:同时在多台主机上添加一个user或查看所有主机的硬件信息,如果没有批量操作工具,设备少于2 ...

  9. Linux学习计划

    用Linux已经有很长一段时间了,先后用过Debian和CentOS,但一直没有系统地去学习,现在一是有时间,二是工作中需要用到,所以准备用心去学习一下. 一.教材 1.主要以<鸟哥Linux& ...

  10. H1标签使用的七大注意事项

    H1标签使用的七大注意事项: 1 每个页面都应该有H1标签,H1标签是每个网页不可缺少的要素. 2 使用H1标签的内容应该简洁明了; 3 H1标签要尽量出现在源文件代码的开头的部分,这样可以让访问者和 ...