Codeforces Round #188 (Div. 2) B. Strings of Power
来源:互联网 发布:帝国cms二次开发 编辑:程序博客网 时间:2024/06/06 00:05
/*题目还是满水的 不过TML了一次 WA了一次 写个blog 纪念一下 涨点教训 */#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;__int64 n,ans;int h[1000005],m[1000005],cnt1,cnt2,cnth,cntm;char s[1000005];void solve(){int i,j,len;cnt1=cnt2=0;len=strlen(s);for(i=0;i<=len-5;i++) // 找出哪些位置出现了“heavy"和"metal" 并将首位置记录在各自数组中 { if(s[i]=='h') { if(s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='v'&&s[i+4]=='y') { h[++cnt1]=i; } } if(s[i]=='m') { if(s[i+1]=='e'&&s[i+2]=='t'&&s[i+3]=='a'&&s[i+4]=='l') { m[++cnt2]=i; } } } h[cnt1+1]=100000000; // 类似贪心 要在最后加一个哨兵 m[cnt2+1]=100000005; ans=0; cnth=cntm=1; while(cnth<=cnt1||cntm<=cnt2) // 开始用的二阶循环 导致TMl 其实一阶完全可以搞定 { if(h[cnth]<m[cntm]) // 若不加哨兵 则cnth=cnt1后会一直执行语句一 { cnth++; } else // 同理m[]也要加哨兵 开始m[]没加WA了一次 { ans+=cnth-1; cntm++; } }}int main(){int i,j,t;while(gets(s)!=NULL){solve();printf("%I64d\n",ans);}return 0;}
- Codeforces Round #188 (Div. 2) B. Strings of Power
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) 447B DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) B.DYZ Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- Codeforces Round #302 (Div. 2) A. Set of Strings
- Codeforces Round #302 (Div. 2) A. Set of Strings
- codeforces Strings of Power
- B. Strings of Power
- B. Strings of Power
- UpdateLayeredWindow和SetLayeredWindowAttributes
- 设计模式(单例、装饰、享元、模板)
- 安卓开发的一些备忘问题
- 微软宣布推出Windows Embedded Compact 2013正式版
- 重载1
- Codeforces Round #188 (Div. 2) B. Strings of Power
- ACE 中 ACE_Mem_Map 类的简单简单测试
- Java Final Keyword
- 可视化调试:基于共享内存发送数据
- Android 星级评分条DEMO
- nfs的使用
- Uboot目录结构
- windows位图与调色板
- IOS 关于取消及延迟执行函数 performSelector 与 cancelPreviousPerformRequestsWithTarget