HDU - 5455 Fang Fang
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.
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 S according to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc Sample Output
Case #:
Case #:
Case #:
Case #: -
Case #:
Case #:
Case #:
Case #: -
Hint Shift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff".
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5455
**************************************************
题意:f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2,给你一个字符串,问你最少有多少个f里面的东西组成
分析:把前两个直接拼接到最后,然后扫C的位置,看后面是否跟着两个f,注意可能含有其他字母,可能全是f
AC代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stdlib.h> using namespace std;
#define N 1010000
#define INF 0x3f3f3f3f char s[N]; int main()
{
int k=,T,i; scanf("%d",&T); while(T--)
{
scanf("%s", s); int f=,ans=;
int len=strlen(s); s[len]=s[];///ffcffc结果是3
s[len+]=s[]; for(i=; i<len; i++)///输入有可能存在其他的字符
{
if(s[i]=='c'||s[i]=='f')
continue ;
else
{
f=;
break;
}
} for(i=;i<len;i++)
{
if(f==)
{
if(s[i]=='c')
{
if(s[i+]=='f'&&s[i+]=='f')
{
i++;
while(i<len&&s[i]=='f')///遇见c跳出
i++;
ans++;///个数加一
i--;
}
else
f=;
}
}
} printf("Case #%d: ",k++);
if(f==)
printf("-1\n");
else if(ans==)///全是f
printf("%d\n", len/+len%);
else
printf("%d\n", ans);
}
return ;
}
HDU - 5455 Fang Fang的更多相关文章
- HDU 5455:Fang Fang 查cff个数
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- 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) 题目思路: ...
- hdu 5459 Jesus Is Here 数学
Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 5459(递推好题)
Jesus Is Here Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)To ...
随机推荐
- 小例子解释wait与notify的区别
系统慢可能有很多种原因,硬件资源不足,语句不优化,结构设计不合理,缺少必要的运维方式.所有的这些问题都可以在阻塞与等待中看出端倪,发现并解决问题. 首先是下载开发工具,磨刀不误砍材工.点此下载 这是一 ...
- MySQL数据库的数据备份和恢复(导入和导出)命令操作语法【转】
不管是Oracle数据库还是SQL Server数据库,每个数据库都有自己的一套数据备份和恢复的方法,MySQL数据库也不例外.MySQL数据库备份和恢复用到了两个命令,分别是“mysqldump”和 ...
- Anaconda 安装概要
Anaconda 作为开源项目,集成了Python的大部分第三方包,如:pandas,Numpy,scipy等. 1. 下载地址:https://www.continuum.io/downloads ...
- mysql加密和解密
MySQL 4.1版本之前是MySQL323加密,MySQL 4.1和之后的版本都是MySQLSHA1加密, (1)以MySQL323方式加密 select old_password('111111 ...
- java之String类型
一:定义 String是复杂类型,是特殊的复杂类型. 二:创建 两种创建形式: String s = "abc"; String s = new String("abc& ...
- 关于C++中的重定位
"标准库定义了4个IO对象,处理输入时使用命名为cin的istream类型对象,这个对象也成为标准输入.处理输出时使用命名为cout的ostream类型对象,这个对象也称为标准输出.标准库还 ...
- Android(对话框)
一.消息对话框 所谓的消息对话框,就是说当你点击按钮弹框,它会弹出一个消息提示你,消息对话框有相应的确定.取消.其他按钮,比如下方: 代码: //消息提示框 public void testOne(V ...
- AIDL机制实现进程间的通讯实例
转载自:http://blog.csdn.net/cjjky/article/details/7562652 ======================================= 在Andr ...
- ZOJ 1655 FZU 1125 Transport Goods
迪杰斯特拉最短路径. 1.every city must wait till all the goods arrive, and then transport the arriving goods t ...
- javascript中关于this的理解
首先看一下这几个定义 this对象是在运行时基于函数的执行环境绑定的:在全局函数中,this等于window,而当函数被视为某个对象的方法调用时,this等于那个对象. 不过,匿名函数的执行环境具有全 ...