HDU 5455:Fang Fang 查cff个数
Fang Fang
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 945 Accepted Submission(s): 393
I promise her. We define the sequence F of
strings.
F0 = ‘‘f",
F1 = ‘‘ff",
F2 = ‘‘cff",
Fn = Fn−1 + ‘‘f", for n > 2
Write down a serenade as a lowercase string S in
a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in F,
or nothing could be done but put her away in cold wilderness.
indicating there are T test
cases.
Following are T lines,
each line contains an string S as
introduced above.
The total length of strings for all test cases would not be larger than 106.
For each test case, if one can not spell the serenade by using the strings in F,
output −1.
Otherwise, output the minimum number of strings in F to
split Saccording
to aforementioned rules. Repetitive strings should be counted repeatedly.
8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc
Case #1: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1HintShift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff".
水题,实际上就是查cff的个数。唯一的坑就是全部是f时要判断一下。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long test;
char a[1000005]; int main()
{
long long i, j, h, k, len, res, res_count;
int flag;
cin >> test;
for (i = 1; i <= test; i++)
{
cin >> a;
len = strlen(a);
flag = 1;
res = 0; for (h = 0; h < len; h++)
{
if (a[h] == 'c')
{
flag = 2;
if (a[(h + 1) % len] == 'f'&&a[(h + 2) % len] == 'f')
{
h = h + 2;
res++;
}
else
{
flag = 0;
break;
}
}
else if (a[h] == 'f')
{
continue;
}
else
{
flag = 0;
break;
}
}
if (flag == 0)
{
cout << "Case #" << i << ": " << -1 << endl;
}
else if (flag == 2)
{
cout << "Case #" << i << ": " << res << endl;
}
else
{
cout << "Case #" << i << ": " << (len+1)/2 << endl;
}
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5455:Fang Fang 查cff个数的更多相关文章
- HDU - 5455 Fang Fang
Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence ...
- hdu 5455 Fang Fang 坑题
Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...
- (字符串处理)Fang Fang -- hdu -- 5455 (2015 ACM/ICPC Asia Regional Shenyang Online)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5455 Fang Fang Time Limit: 1500/1000 MS (Java/Others) ...
- Fang Fang HDU - 5455 (思维题)
Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 = ...
- hdu 5455(字符串处理)
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total S ...
- hdu 5455 (2015沈阳网赛 简单题) Fang Fang
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...
- HDU 5455 Fang Fang 水题,但题意描述有问题
题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路: ...
- Ant Trip HDU - 3018(欧拉路的个数 + 并查集)
题意: Ant Tony和他的朋友们想游览蚂蚁国各地. 给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 保证这M条边都不同且不会存在同一点的自环边. 也就 ...
- More is better(hdu 1856 计算并查集集合中元素个数最多的集合)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
随机推荐
- IdentityServer4专题之七:Authorization Code认证模式
(1)identityserver4授权服务器端 public static class Config { public static IEnumerable<IdentityResource& ...
- struts2令牌(token)内部原理
小菜最近接触了struts2中的令牌知识,由于该知识点比较重要,因此想弄明白些,于是满怀信心的上网查阅资料,结果让小菜很无奈,网上的资料千篇一律,总结出来就一句话:“访问页面时,在页面产生一个to ...
- java string常用的占位符形式
自己在这里总结了三种占位符形式:看下面代码即可 String stringFormat = "lexical error at position %s, encountered % ...
- VS中MFC项目文件特别大的解决办法
转 来自http://m.zhizuobiao.com/vc/vc-18082800177/ 自己插个眼 项目文件比较大因为 项目下有个隐藏文件夹.vs 下面是解决办法 本文主要向大家介绍了VC编程 ...
- 并行执行 Job【转】
有时,我们希望能同时运行多个 Pod,提高 Job 的执行效率.这个可以通过 parallelism 设置. 这里我们将并行的 Pod 数量设置为 2,实践一下: Job 一共启动了两个 Pod,而且 ...
- 用python实现在手机查看小姐姐的电脑在作什么!
看上心意的小姐姐,想看她平时都浏览什么网页,如何才能看她的桌面呢,都说Python很厉害,这次我们做一个利用移动端访问电脑来查看电脑的界面的神器!不知道大家以前有没有做过这方面的东西呢?也许大家听起来 ...
- 025、MySQL字符串大小写转化函数,文本转化大写,文本转化小写
#变大写 SELECT UPPER('abcdABCD123a'); #ABCDABCD123A SELECT UCASE('abcdABCD123a'); #ABCDABCD123A #变小写 SE ...
- edge浏览器两个标签页localStorage不同步,解决办法
今天遇到个奇怪的问题,edge两个标签页之间的localStorage值不同步,网上说ie和edge如果想让localStorage值同步,需要主动出发localStorage的change事件 wi ...
- CPU与内存
一.存储单元内存有被划分为若干个存储单元,每个存储单元可存放1一个字节,即8个二进制位.因此内存的最小寻址单位是以字节进行的,每个存储单元都有一个编号.比如1GB的内存,可以储存1024*1024*1 ...
- Mac 设置git的template
1.在home目录下修改.gitconfig(没有新建) 2. 在home下新建 .setCommitMsg 文件 3.然后将一下内容复制到文件中 # <类型>: (类型的值见下面描述) ...