题意:在他眼前有一个小写字母组成的字符串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 (水题)的更多相关文章

  1. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  2. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  3. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  4. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  5. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  6. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  7. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. HDU—2021-发工资咯(水题,有点贪心的思想)

    作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...

  9. HDU 5907 Find Q dp

    Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...

随机推荐

  1. COdevs 1251 括号

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 计算乘法时,我们可以添加括号,来改变相乘的顺序,比如计算X1, X2, X3, X4 ...

  2. python学习之-- 面向对象

    面向对象(简写:OOP) 面向对象编程定义:利用类和对象来创建各种模型,来实现对真实世界的描述. 优点:使程序更容易理解和维护以及扩展代码. 类定义:用来描述具有相同的属性和方法的对象的集合.(简单讲 ...

  3. 关于用String Calender类 计算闰年的Demo

    package cn.zmh.zuoye; import java.util.Calendar; public class StringRun { public static void main(St ...

  4. EF关联

    public CustomerMap() { this.ToTable("Customer"); this.HasKey(c => c.Id); this.Property( ...

  5. Java多线程导致的的一个事物性问题

    业务场景 我们如今有一个类似于文件上传的功能.各个子网站接受业务,业务上传文件,各个子网站的文件须要提交到总网站保存.文件是按批次提交到总网站的,也就是说,一个批次以下约有几百个文件. 考虑到白天提交 ...

  6. Angular结构简单介绍

    在当前项目目录下,使用Angular-CLI生成一个组件:heroes ng generate component heroes 主界面(也就是一个主模块+多个单模块,例如我们创建的heroes(单模 ...

  7. Android ViewPager实现Tabhost选项卡底部滑块动态滑动过渡

     <Android ViewPager实现Tabhost选项卡底部滑块动态滑动过渡> 之前基于github上的第三方开源控件ViewPagerIndicator的UnderlinePa ...

  8. slice,substr,substring的区别

    <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Prope ...

  9. 对于api安全性的思考

    目前的情况下api被很多地方应用,随之而来的是api的安全性问题. 我所认识到的安全性问题有以下几个方面: 1.DDoS(拒绝服务攻击),接口被恶意调用,使真实的用户无法享受到正常畅通的服务.     ...

  10. c中常用的关键字static const volatile

    在C语言中,关键字static有三个明显的作用:1). 在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变.2). 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数 ...