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的理解……不过不能自己写出来还真是弱…… /************* ...
随机推荐
- Microsoft Dynamics CRM4.0编程---说明
Introduction(说明) If your organization has customers, you need a software system to help you manage y ...
- IE的CSS相关的BUG(整理一)
本来不想弄这个ie的bug的,真的很想让它快点死掉,可是事与愿违啊,没办法,还是贴出来,以备自用. 这个网页(http://haslayout.net/css/index)上例举了所有的IE和CSS相 ...
- Android 自定义View (四) 视频音量调控
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24529807 今天没事逛eoe,看见有人求助要做一个下面的效果,我看下面一哥们说 ...
- Java基础知识强化73:正则表达式之分割功能
1. 分割功能: 使用String的split方法,split方法:根据给定正则表达式的匹配拆分字符串.如下: public String[] split(String regex): 2. 案例: ...
- 二叉排序树BST代码(JAVA)
publicclassTest{ publicstaticvoid main(String[] args){ int[] r =newint[]{5,1,3,4,6,7 ...
- 【网络流#1】hdu 3549 - 最大流模板题
因为坑了无数次队友 要开始学习网络流了,先从基础的开始,嗯~ 这道题是最大流的模板题,用来测试模板好啦~ Edmonds_Karp模板 with 前向星 时间复杂度o(V*E^2) #include& ...
- 小学生之SpringMVC
1. Springmvc是什么? Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基 ...
- Java 小型学生管理系统心得
这个学生管理系统相对来说比较简单,主要就是复习下java怎么连接数据库,然后你怎么来实现这个功能,我简单的说下思路吧. 首先你要构思好这个界面,他包括增删查改这些基本功能,然后你去分析这些功能都能怎么 ...
- 阿里云linux的nginx下面配置多站点
假设有服务器ip为 114.214.85.35 域名1为 www.jieshendada.cn 域名2为 www.jieshenxiaoxiao.cn 1.首先打开nginx域名配置文件存放目录:/ ...
- ajax调用webservice(二) 跨域。
所需工具与项目结构同(一). service.asmx中代码如下: using System; using System.Collections.Generic; using System.Web; ...