【HDU - 5455】Fang Fang(水题,有坑)

题干:

Fang Fang says she wants to be remembered. 
I promise her. We define the sequence FF of strings. 
F0 = ‘‘f",F0 = ‘‘f", 
F1 = ‘‘ff",F1 = ‘‘ff", 
F2 = ‘‘cff",F2 = ‘‘cff", 
Fn = Fn−1 + ‘‘f", for n > 2Fn = Fn−1 + ‘‘f", for n > 2 
Write down a serenade as a lowercase string SS in a circle, in a loop that never ends. 
Spell the serenade using the minimum number of strings in FF, or nothing could be done but put her away in cold wilderness.

Input

An positive integer TT, indicating there are TT test cases. 
Following are TT lines, each line contains an string SS as introduced above. 
The total length of strings for all test cases would not be larger than 106106.

Output

The output contains exactly TT lines. 
For each test case, if one can not spell the serenade by using the strings in FF, output −1−1. Otherwise, output the minimum number of strings in FF to split SSaccording to aforementioned rules. Repetitive strings should be counted repeatedly.

Sample Input

8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc

Sample Output

Case #1: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1

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".

题目大意:定义递推式F为f(0)='f',f(1)='ff',f(2)='cff',f(n)=f(n-1)+'f',给出一个首位相连的字符串s,问组成s至少需要多少个F,如果F不能组成s,输出-1.

解题报告:

就是看有多少个c就行了,注意题目中说字符串是小写字母串,但是没说只含有c和f

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cctype>
using namespace std;
typedef long long ll;int n,len;
char str[1000100];
int main()
{int t,i,j,k,cnt=0,nn,ans;bool nf;cin>>t; getchar();for(;t;t--){scanf("%s",str);nn=nf=0;len=strlen(str);printf("Case #%d: ",++cnt);if(len<=2){for(i=0;i<len&&str[i]=='f';i++);if(i<len) puts("-1");else puts("1");continue;}for(i=0;i<len;i++){if(str[i]=='c'){if(i<len-1&&str[i+1]=='c'||i==len-1&&str[0]=='c')//ccnf=1;//cfcelse if(i<len-2&&str[i+1]=='f'&&str[i+2]=='c'||i==len-2&&str[i+1]=='f'&&str[0]=='c'||i==len-1&&str[0]=='f'&&str[1]=='c')nf=1;else nn++;if(nf==1) break;}else if(str[i]!='f')nf=1;}if(nf) puts("-1");else {if(nn==0)ans=len/2+len%2;else ans=nn;printf("%d\n",ans);}}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440242.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

npm安装与卸载和cordova及ionic项目打包调试等相关命令总结归纳

一、安装和卸载node和npm的命令 1、Mac系统彻底卸载npmsudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}2、因网络问题导致包安装失败的安全解决方法cd到对应项目之下&#xff0c;如果有权限问题前加sudorm -rf node_modules/npm c…

Apollo自动驾驶入门课程第⑤讲 — 感知(下)

目录 1. 卷积神经网络 2. 检测与分类 3. 跟踪 4. 分割 5. Apollo感知 6. 传感器数据比较 7. 感知融合策略 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿波君 Apollo开发者社区 8月29日 上一篇文章中&#xff0c;我们发布了无人驾驶技术的 感知篇…

【 HDU - 5459】Jesus Is Here(dp)

题干&#xff1a; Ive sent Fang Fang around 201314 text messages in almost 5 years. Why cant she make sense of what I mean? But Jesus is here!" the priest intoned. Show me your messages." Fine, the first message is s1‘‘c"s1‘‘c" a…

TextRank算法原理和提取关键词的主要过程详解 计算句子相似度 计算句子重要性公式

1、TextRank计算句子相似度和句子重要性的公式 2、TextRank算法提取关键词的过程 3、TextRank建立关键词无向图

Apollo自动驾驶入门课程第⑥讲 — 预测

目录 1. 简介 2. 不同的预测方式 3. 基于车道序列的预测 4. 障碍物状态 5. 预测目标车道 6. 递归神经网络 7. 递归神经网络在目标车道预测的应用 8. 轨迹生成 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a;涛涛CV Apollo开发者社区 9月6日 上一篇文…

使用PDF.js实现前端和手机端网页预览PDF文件(可定制,支持本地文件、Base64编码和远程URL跨域方式)

1.插件下载地址&#xff1a;https://mozilla.github.io/pdf.js/ 下载后解压pdfjs-1.10.88-dist.zip文件后得到&#xff1a; 2.把pdfjs-1.10.88-dist放到项目静态资源中&#xff0c;在自己的页面中通过iframe链接到pdfjs-1.10.88-dist/web/viewer.html文件中。 3.访问自己的页…

【HDU - 5878】I Count Two Three(打表)

题干&#xff1a; I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started several months ago. We found out the home address of the enlightened agent Icount2three and decided to draw him out. Millions of missile…

移动互联网浩荡十年 有的升腾,有的陨落

原创&#xff1a; 颜西龙 猎云网 &#xff08;ilieyun&#xff09;1周前 中国移动互联网的十年&#xff0c;是波澜壮阔、荡气回肠的十年。本文回溯了这段历史&#xff0c;在这十年间里&#xff0c;有的企业升腾&#xff0c;有的企业陨落。 2011年8月16日&#xff0c;北京798艺术…

原生JS动态计算输入框文本内容的宽度,当内容宽度超过输入框的宽度时可控

需求场景&#xff1a;左边输入框输入内容&#xff0c;右边输入框用placeholder展示&#xff0c;当placeholder的内容宽度超过右边输入框的宽度时&#xff0c;placeholder强行替换为“请选择” 注意事项&#xff1a;1、左右输入框的大小、样式都无关&#xff1b; 2、实际业务中…

【HDU - 5881】Tea(思维,找规律)

题干&#xff1a; Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance of the universe. Alice knows that. Alice wants to teach you the art of pouring tea. Alice has a pot of tea. The exact volume of tea is…

Apollo自动驾驶入门课程第⑦讲 — 规划(上)

目录 1. 规划简介 2. 将地图转为图形 3. 路径查找算法&#xff1a;A* 4. 轨迹生成 5. Fernet坐标系 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿波君 Apollo开发者社区 9月13日 上周我们发布了无人驾驶技术的 预测篇&#xff0c;简要介绍了预测的…

JS正则表达式常见场景下的用法总结

&#xff08;一&#xff09;前置知识总结&#xff1a; 1. 正则表达式 /xxxx/[标识] 其中的标识含义 •g &#xff08;全文查找&#xff09; •i &#xff08;忽略大小写&#xff09; •m &#xff08;多行查找&#xff09; 2. 正则表达式创建的两种方式&#xff08;等价&#…

【HDU - 5882】Balanced Game (找规律,思维)

题干&#xff1a; Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper", and "scisso…

Apollo自动驾驶入门课程第⑧讲 — 规划(下)

目录 1. 路径-速度解耦规划 2. 路径生成与选择 3. ST图 4. 速度规划 5. 优化 6. 路径-速度规划的轨迹生成 7. Lattice规划 8. ST轨迹的终止状态 9. SL轨迹的终止状态 10. Lattice规划的轨迹生成 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿…

网络编程懒人入门(五):快速理解为什么说UDP有时比TCP更有优势

转自即时通讯网&#xff1a;http://www.52im.net/ 本文观点仅作参考&#xff0c;请根据自已系统的应用场景合理地选择数据传输层协议即可&#xff0c;无需盲目崇拜大牛言论。 1、前言 对于即时通讯开者新手来说&#xff0c;在开始着手编写IM或消息推送系统的代码前&#xff…

CSS定位总结:position=static/relative/absolute/fixed时的区别、top/bottom/left/right与margin外边距的运用

准备布局&#xff1a; <!DOCTYPE html> <html> <head> <style> *{ margin:0; padding:0; } .base-container{width: 500px;height: 500px;background-color:lightgray;border:1px dashed red; } .base-compare {width:200px;height:100px;background…

【HDU - 5883】The Best Path(判断欧拉回路)

题干&#xff1a; Alice is planning her travel route in a beautiful valley. In this valley, there are NN lakes, and MM rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up …

网络编程懒人入门(六):史上最通俗的集线器、交换机、路由器功能原理入门

转自即时通讯网&#xff1a;http://www.52im.net/ 本文引用了知乎网友“薛定谔不在家”的部分文字内容&#xff0c;感谢原作者的分享。 1、前言 即时通讯网整理了大量的网络编程类基础文章和资料&#xff0c;包括《TCP/IP协议 卷1》、《[通俗易懂]深入理解TCP协议》系列、《…

总结JSON.parse()报错VM71:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0等之类的问题

问题场景&#xff1a;在调试前端应用的时候经常出现形如“Uncaught SyntaxError: Unexpected”之类的令人头疼觉得莫名其妙的问题&#xff1b;所以有必要总结整理一下关于JSON.parse()这个API方法的注意事项。以便在以后的开发中出现类似的问题能第一时间想到可能是这个方法的参…

【HDU - 5884】Sort(k叉哈夫曼树,优化tricks,两个队列代替优先队列)

题干&#xff1a; Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from Alice. Alice will give Bob NN sorted sequences, and the ii-th sequence includes aiai elements. Bob need to merge all of these sequences. H…