hihocoder 1061.Beautiful String
题目链接:http://hihocoder.com/problemset/problem/1061
题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings的子串:连续递增且数量相等的字母。
照着题目分析翻译的代码。。。
分析得很到位呢,大赞 ^_^
http://hihocoder.com/discuss/question/2083
hiho的题目其实挺好的,有专题,有分析,有代码 & 思路参考。。。
想想出来工作那么久,浮躁的心啊,一个多快两个月没碰啦,得捡回来呢~~~继续ACM哇,为T-shirt fighting !
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = **; // 10MB的字节(1024字节=1KB,1024K=1M)
char str[maxn], s[maxn];
int cnt[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, cas;
while (scanf("%d", &cas) != EOF) {
while (cas--) {
scanf("%d", &n);
scanf("%s", str);
memset(cnt, , sizeof(cnt));
int num = ;
int c = ;
for (int i = ; i < n; i++) {
if (str[i] == str[i+]) {
c++;
}
else {
s[num] = str[i];
cnt[num++] = c;
c = ;
}
} bool flag = false;
for (int i = ; i < num; i++) {
if (s[i-]+ == s[i] && s[i]+ == s[i+] && cnt[i-] >= cnt[i] && cnt[i] <= cnt[i+]) {
flag = true;
break;
}
}
printf("%s\n", flag ? "YES" : "NO");
}
}
return ;
}
hihocoder 1061.Beautiful String的更多相关文章
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- hiho一下:Beautiful String
hiho一下:Beautiful String 记不清这是 hiho一下第几周的题目了,题目不难,不过对于练习编程,训练思维很有帮助.况且当时笔者处于学习算法的早期, 所以也希望刚接触算法的同学能多去 ...
- CF1328B K-th Beautiful String
CF1328B K-th Beautiful String,然而CF今天却上不去了,这是洛谷的链接 题意 一个长度为\(n\)的字符串,有2个\(\texttt{b}\)和\(n-2\)个\(\tex ...
- hihoCoder 1596 : Beautiful Sequence
Description Consider a positive integer sequence a[1], ..., a[n] (n ≥ 3). If for every 2 ≤ i ≤ n-1, ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- HackerRank beautiful string
问题 https://vjudge.net/problem/HackerRank-beautiful-string 给一个字符串S,可以任意取走S中的两个字符从而得到另外一个字符串P,求有多少种不同的 ...
- B. Pasha and String
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm & String<Problem L>
L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others) Memory Limit: 43000/43000KB (Java/ ...
- Pasha and String(思维,技巧)
Pasha and String Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- JS替换函数
var id= id.replace(/\,/g, "','"); 记一下,
- [AngularJS] jQuery时代
抹平浏览器差异的jQuery出现了 jQuery有什么 jQuery使得开发无刷新动态页面(AJAX)或者单页应用(SAP)变得 相当简单. 标准的HTML页面是静态的,被浏览器渲染后就产生了一个DO ...
- 2012Chengdu B (快速组合数)
B - Candy Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- JSON格式转换(javascript)
使用ajax从后台抓取数据后,如果有多个值,可以使用json传值. ajax例子如下,在返回的类型里面,可以是文本型(text),JSON格式(json),超文本类型(html),XML文件类型(xm ...
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- ios本地化多语言支持
右键 -> new file -> resources -> strings file 一定要命名为: Localizable.strings 点击这个文件 -> xocde ...
- DOM的相关优化
为什么要进行DOM优化? DOM对象本身也是一个js对象,所以严格来说,并不是操作这个对象慢,而是说操作了这个对象后,会触发一些浏览器行为,比如布局(layout)和绘制(paint). 首先先说一些 ...
- Validform —— 再也不用担心“表单验证”!
<!doctype html> <html> <head> <meta content="text/html" charset=" ...
- 9.4---集合子集(CC150)
这题非常复杂.牛客网上对应的题目对结果要求比较苛刻,所以要调整. 整体思路是:先放进去一个,然后第二个来的时候插入到已有的,并且把自己也放进去. public static ArrayList< ...
- centos 设置永久dns
最近在折腾一个问题. 由于服务器的带宽是联通5M, 不稳定.而且所处的网络的dns解析貌似老出问题,每隔一定周期解析时间特别长. 于是乎,想在本地做一个dns,这样可以减少dns解析时间,并做些静态配 ...