HDU 5907 Find Q (水题)
题意:在他眼前有一个小写字母组成的字符串SSS,他想找出SSS的所有仅包含字母'q'的连续子串。
析:这个题,很容易发现,有 n 个连续个q,就是前 n 项和。注意不要超 int。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
char s[maxn];
LL sum[maxn]; int main(){
sum[0] = 0;
for(int i = 1; i <= 100002; ++i) sum[i] = sum[i-1] + i;
int T; cin >> T;
while(T--){
scanf("%s", s);
n = strlen(s);
LL ans = 0;
int cnt = 0;
for(int i = 0; i < n; ++i){
if(s[i] == 'q') ++cnt;
else if(cnt){
ans += sum[cnt];
cnt = 0;
}
}
ans += sum[cnt];
cout << ans << endl;
}
return 0;
}
HDU 5907 Find Q (水题)的更多相关文章
- hdu 1106:排序(水题,字符串处理 + 排序)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 4950 Monster (水题)
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...
- HDU 4813 Hard Code 水题
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDOJ/HDU 2560 Buildings(嗯~水题)
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...
- HDOJ(HDU) 1859 最小长方形(水题、、)
Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...
- HDU - 1716 排列2 水题
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU—2021-发工资咯(水题,有点贪心的思想)
作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵 但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...
- HDU 5907 Find Q dp
Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...
随机推荐
- 【2018 Multi-University Training Contest 1】
01:https://www.cnblogs.com/myx12345/p/9362221.html 02:https://www.cnblogs.com/myx12345/p/9382267.htm ...
- hdu3306:Another kind of Fibonacci
A(0)=A(1)=1,A(i)=X*A(i-1)+Y*A(i-2),求S(n)=A(0)^2+A(1)^2+A(2)^2+A(3)^2+……+A(n)^2. 这个矩阵有点毒.. #include&l ...
- P1195 口袋的天空 洛谷
https://www.luogu.org/problem/show?pid=1195 题目背景 小杉坐在教室里,透过口袋一样的窗户看口袋一样的天空. 有很多云飘在那里,看起来很漂亮,小杉想摘下那样美 ...
- Meteor package.js
在本章中,我们将学习如何创建自己的 meteor 包. 创建包 让我们添加在桌面上的新文件夹用来创建新的包.使用命令提示符窗口执行如下命令. C:\Users\Administrator\Deskto ...
- swiper插件制作轮播图swiper2.x和3.x区别
swiper3.x仅仅兼容到ie10+.比較适合移动端. swiper3.x官网 http://www.swiper.com.cn/ swiper2.x能够兼容到ie7+.官网是http://swi ...
- Qt Quick 图像处理实例之美图秀秀(附源代码下载)
在<Qt Quick 之 QML 与 C++ 混合编程具体解释>一文中我们解说了 QML 与 C++ 混合编程的方方面面的内容,这次我们通过一个图像处理应用.再来看一下 QML 与 C++ ...
- Input系统—ANR原理分析(转)
一. 概述 当input事件处理得慢就会触发ANR,那ANR内部原理是什么,哪些场景会产生ANR呢. “工欲善其事必先利其器”,为了理解input ANR原理,前面几篇文章疏通了整个input框架的处 ...
- HDU 5288(OO’s Sequence-区间互质情况统计)
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- iOS用户体验之-modal上下文
iOS用户体验之-modal上下文 何为模态视图,它的作用时聚焦当前.获得用户的注意,用户仅仅有完毕模态的任务才 退出模态视图.否则你将不能运行app的任务,比如,alert view,model v ...
- Scrum 时间估算
在新公司里,不懂软件工程的产品经理经常逼迫研发人员作出很不靠谱的时间估算.常见场景有下面这些: 需求未细化的情况下要求给出时间估算:比如,就一句话描述需要做一个什么样的功能,但是具体页面长什么样,交互 ...