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) ...
随机推荐
- 可旋转Treap(树堆)总结
树堆,在数据结构中也称Treap,是指有一个随机附加域满足堆的性质的二叉搜索树,其结构相当于以随机数据插入的二叉搜索树.其基本操作的期望时间复杂度为O(logn).相对于其他的平衡二叉搜索树,Trea ...
- Jenkins + git + maven 安装
1.jenkins安装 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo ...
- shell命令、调度工具、后台执行线程和软连接
一.shell命令 1.后缀.sh 第一行需要加#!/bin/bash 没有的话,需呀sh 命令执行 示例test.sh: #!/bin/bash date ./test.sh 提示没有权限,此时,需 ...
- 吴裕雄--天生自然JAVA数据库编程:执行数据库更新操作
import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.Statement ; public clas ...
- 转《Python爬虫学习系列教程》学习笔记
http://www.cnblogs.com/xin-xin/p/4297852.html
- docker安装mysql中注意事项
前言 怎么安装docker和拉mysql镜像不是本文的重点,在这里我主要讲我安装mysql容器的三个注意事项:启动容器, 修改密码,远程登录 run容器 docker run -di --name f ...
- 快速为Eclipse配置PyDev插件
想学习Python,查询网络之后发现PyDev是很好的插件,所以就想为Eclipse配置它.结果在整个配置的过程中出现了各种问题,版本问题,重复问题,反正乱七八糟的,本身安装一次的时间就很长,中间出现 ...
- mysql提示 Lock wait timeout exceeded解决办法 事务锁死
查询 select concat('KILL ',id,';') from information_schema.processlist; 复制结果 新建sql脚本粘贴并执行
- 移动端 三段式布局 (flex方式)
分享一种平时用的三段式布局(flex) 主要思路是 上中下 header&footer 给高度 main 占其余部分 html 部分 <div class='wrap'> ...
- Codeforces Round #611 (Div. 3)
原题面:https://codeforces.com/contest/1283 A.Minutes Before the New Year 题目大意:给定时间,问距离零点零分还有多久? 分析:注意一下 ...