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 ...
随机推荐
- .net MVC 中“MvcPager” 插件的简单使用。
.net MVC 中提供了一个分页组件"MvcPager",用起来还算方便,实用性较强. 简单写一下使用方法,如有不足的地方,请各位大大给小弟指正出来. 一.准备工作 使用这个组件 ...
- vsftp 虚拟用户
首先安装vsftp db-4wiki mkdir -p /opt/ftp 创建用户 sudo useradd virtual -d /opt/ftp -s /bin/false sudo chown ...
- 【转】MapReduce的优化
相信每个程序员在编程时都会问自己两个问题“我如何完成这个任务”,以及“怎么能让程序运行得更快”.同样,MapReduce计算模型的多次优化也是为了更好地解答这两个问题. MapReduce计算模型的优 ...
- 基于Debian系统配置Nginx环境的Node.js应用教程
Node.js,是当前比较流行的能够动态的快速响应内容的JavaScript框架,在有些环境下比我们使用的PHP应用都能够提高效率.目 前,Node.js可以与我们常用的Nginx.Apache等服务 ...
- Dubbo.xml配置源-Dubbo.xsd分析
我们使用Dubbo时,一般都会使用xml配置基本信息,如项目名称(application).注册中心(register).协议(protocal).服务(service),如下所示: 1 2 3 ...
- [JS思路]运动框架思路
匀速运动的思路一: 1.先清除动画,再加载动画 2.方向dir有正值和负值,可以通过 目标值 > 当前值 往右移动,即正数 目标值 < 当前值 往右移动,即负数 来进行判断:dir = ...
- POJ 2305 Basic remains(进制转换)
题目链接:http://poj.org/problem?id=2305 ime Limit: 1000MS Memory Limit: 65536K Total Submissions: 5326 ...
- PAT 团体程序设计天梯赛-练习集 L1-008. 求整数段和
给定两个整数A和B,输出从A到B的所有整数以及这些数的和. 输入格式: 输入在一行中给出2个整数A和B,其中-100<=A<=B<=100,其间以空格分隔. 输出格式: 首先顺序输出 ...
- PAT 团体程序设计天梯赛-练习集 L1-007. 念数字
输入一个整数,输出每个数字对应的拼音.当整数为负数时,先输出“fu”字.十个数字对应的拼音如下: 0: ling 1: yi 2: er 3: san 4: si 5: wu 6: liu 7: qi ...
- Save Update saveOrUpdate delete
参考:Hibernate Session的saveOrUpdate()方法 saveOrUpdate与Update的作用 Hibernate Delete query Hibernate Basics ...