HDU 5056 - Boring count
来源:互联网 发布:mac切换页面快捷键 编辑:程序博客网 时间:2024/06/05 00:43
题意
统计一个字符串中子串每个字符最多重复k次的子串。
思路
用pos记录位置,当碰到cnt>k的时候就往前移
代码
#include <cstdio>
#include <stack>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <cmath>
#define LL long long
#define lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define F first
#define S second
#define ROP freopen("input.txt", "r", stdin);
#define BitCount(x) __builtin_popcount(x)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const int MAXN = 1e5 + 100;
const int MOD = 20071027;
typedef pair<int, int> pii;
typedef vector<int>::iterator viti;
typedef vector<pii>::iterator vitii;
char str[MAXN];
int cnt[30];
int main()
{
//ROP;
int n, i, j, last, T, k;
scanf("%d", &T);
while (T--)
{
MS(cnt, 0);
int pos = 1;
scanf("%s", str + 1);
scanf("%d", &k);
int len = strlen(str + 1);
LL ans = 0;
for (i = 1; i <= len; i++)
{
cnt[str[i] - 'a']++;
while (cnt[str[i] - 'a'] > k)
{
cnt[str[pos] - 'a']--;
pos++;
}
ans += i - pos + 1;
}
cout << ans << endl;
}
return 0;
}
0 0
- HDU 5056 - Boring count
- hdu 5056Boring count
- hdu 5056 Boring count
- hdu 5056 Boring count
- HDU 5056Boring count
- HDU 5056 Boring Count --统计
- [周赛] HDU-5056 Boring count
- HDU 5056 Boring count(窗口滑动法)
- HDU 5056 Boring count(贪心)
- HDU 5056 Boring count(数学)
- hdu 5056 Boring count ( 窗口转移法)
- hdu 5056 Boring count (窗口滑动)
- hdu 5056 Boring count(尺取法)
- HDU 5056 Boring count(滑动窗口)
- HUD 5056 Boring count
- hdoj-5056-Boring count
- HDU 5056 Boring count 字符串处统计+滑动窗口法
- HDU-5056-Boring count-周赛4补题
- 理解ThreadLocal
- linux grep命令详解
- JQuery DataTables 列自定义数据类型排序
- 通过二维码进行产品促销
- 支付宝,网银在线,快钱 3大支付接口的集成与对比,统合实现
- HDU 5056 - Boring count
- android官方侧滑菜单DrawerLayout详解
- hdu 4597 记忆化搜索
- hdoj 5045 (dp 状态压缩)
- RabbitMQ 入门
- java基础:基本数据的自动装拆箱
- 问题反思
- find中的-print0和xargs中-0的奥妙
- 前端领域存在“架构师”吗