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) ...
随机推荐
- Day2-F-A Knight's Journey POJ-2488
Background The knight is getting bored of seeing the same black and white squares again and again an ...
- 「JSOI2007」建筑抢修
传送门 Luogu 解题思路 显然先把所有楼按照报废时间递增排序. 然后考虑 \(1\cdots i-1\) 都能修完, \(i\) 修不完的情况. 显然我们在这 \(i\) 个里面至多只能修 \(i ...
- 通用dao的demo
代码片段 1. [代码]整型映射工具 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 package org.dave.common.databas ...
- Lua生成比较理想的随机数的方法
lua需要生成随机数的需求也是很常见的,为了生成看起来更随机的数字,我们需要注意以下几点 我们也需要给随机数设置随机数种子:math.randomseed(xx) lua对随机数种子也是有一定要求的: ...
- loadrunner controller查看参数日志
1.在generator,我们用这个语句来输出参数:lr_output_message("目录为%s", lr_eval_string("{NewParam}" ...
- C++字符集和词法记号以及符号常量
C++字符集 大小写的英文字母:A~Z,a~z 数字符号:0~9 特殊字符:!#%*()等 关键字:C++预定义的单词 标识符:程序员声明的单词,它命名程序正文中的一些实体 文字:在程序中直接使用符号 ...
- 第3节 sqoop:7、通过java代码远程连接linux执行shell命令
数据库的数据同步软件sqoop 数据同步 关系型数据库到大数据平台 任务:sqoop 是批量导入数据太慢,如何做到实时的数据同步 实时的数据同步工具: canal 阿里开源的一个数据库数据实时同步的软 ...
- esxi命令行强行关闭虚拟机
目的:强行关闭通过前端界面无法关闭的ESXI虚拟机 环境:esxi5.1-esxi6.5 背景:如果esxi下面某一台vm死机了,并且esxi的控制台卡死不能用,为了不影响同一个esx下其他的vm正常 ...
- CC26XX开发
[CC26XX开发] 2016-01-26 [CC2650 入门] CC2650 sensortag入门 http://processors.wiki.ti.com/index.php/CC2650_ ...
- Spark Scheduler 模块(上)
在阅读 Spark 源代码的过程中,发现单步调试并不能很好的帮助理解程序.这样的多线程的分布式系统,更好的阅读源代码的方式是依据模块,分别理解. 在包 org.apache.spark 下面有很多 ...