whust #0.1 I - Laughing Out Loud
2015-08-09 16:13
246 查看
I - Laughing Out Loud
Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice Gym 100589I
Description
standard input/output
Little Toojee was a happy go lucky boy. He seemed to find most, if not all, things funny. One day he read a word and started laughing a lot. Turns out that the word consisted only of the letters L and O. Whenever he saw the subsequence ‘LOL’ in the word, he laughed for 1 second. Given t strings, find out for how long Toojee laughed on seeing each string.
Input
The first line contains t queries. This is followed by t lines each containing one string S. String S consists only of capital alphabets.
Output
Output for each string on a new line.
Constraints
1 ≤ t ≤ 10
1 ≤ |S| ≤ 105
Sample Input
Input
Output
Hint
Test1: On observation, we can tell that there is only 1 occurrence of LOL.
Test2: Let the string be 0-indexed and let V = {a, b, c} denote the indices that make up the string “LOL”, where a is index of the 1st ‘L’, b is index of the ‘O’ and c is the index of the 2nd ‘L’. So, V can be {0, 1, 2}, {2, 3, 4}, {0, 1, 4} and {0, 3, 4}. We see that there are 4 occurrences of the string “LOL”.
又是求有多少种组合的题.
和上次cf那道求等比数列的非常像.
View Code
Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice Gym 100589I
Description
standard input/output
Little Toojee was a happy go lucky boy. He seemed to find most, if not all, things funny. One day he read a word and started laughing a lot. Turns out that the word consisted only of the letters L and O. Whenever he saw the subsequence ‘LOL’ in the word, he laughed for 1 second. Given t strings, find out for how long Toojee laughed on seeing each string.
Input
The first line contains t queries. This is followed by t lines each containing one string S. String S consists only of capital alphabets.
Output
Output for each string on a new line.
Constraints
1 ≤ t ≤ 10
1 ≤ |S| ≤ 105
Sample Input
Input
2 LOL LOLOL
Output
1 4
Hint
Test1: On observation, we can tell that there is only 1 occurrence of LOL.
Test2: Let the string be 0-indexed and let V = {a, b, c} denote the indices that make up the string “LOL”, where a is index of the 1st ‘L’, b is index of the ‘O’ and c is the index of the 2nd ‘L’. So, V can be {0, 1, 2}, {2, 3, 4}, {0, 1, 4} and {0, 3, 4}. We see that there are 4 occurrences of the string “LOL”.
又是求有多少种组合的题.
和上次cf那道求等比数列的非常像.
/************************************************************************* > File Name: code/whust/#0.1/II.cpp > Author: 111qqz > Email: rkz2013@126.com > Created Time: 2015年08月09日 星期日 16时00分44秒 ************************************************************************/ #include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<map> #include<set> #include<queue> #include<vector> #include<stack> #define y0 abc111qqz #define y1 hust111qqz #define yn hez111qqz #define j1 cute111qqz #define tm crazy111qqz #define lr dying111qqz using namespace std; #define REP(i, n) for (int i=0;i<int(n);++i) typedef long long LL; typedef unsigned long long ULL; const int inf = 0x7fffffff; int main() { int T; cin>>T; string st; while (T--) { cin>>st; int len = st.length(); LL p=0,q=0; LL ans = 0 ; for ( int i = 0 ; i < len ; i ++) { if (st[i]=='L') { p++; ans = ans + q; } else { q = q+ p; //p为L的个数,q表示前面有"LO"组合的个数 } } cout<<ans<<endl; } return 0; }
View Code
相关文章推荐
- leetcode 110 —— Balanced Binary Tree
- Python3之OS模块文件操作
- 081 Search in Rotated Sorted Array II[Leetcode]
- GitHub超详细图文攻略
- 10271 - Chopsticks (DP)
- scala类的定义和可变长度参数
- PowerDesigner中Table视图同时显示Code和Name
- 向EditText中添加图片
- 两个月后才更新一篇。。。。LIB和DLL的区别
- MySQL的数据类型
- C++函数模板 模板实例化、具体化
- HDOJ1829 A Bug's Life(并查集)
- C语言-01-基本语法
- 嵌入CEF到MFC程序
- 设计模式--享元模式
- 实现RTP协议的h.264传输
- jquery代码阅读jQuery.makeArray()
- 二叉树的基本操作(定义、遍历、高度、生成)【数据结构】
- 【测试自动化6】城市电话号码 java
- 线程模式