Fang Fang HDU - 5455 (思维题)
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.
InputAn 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.OutputThe 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". 题意很简单不说了。
题解:sumf记录f的个数,然后遇见一个c判断一下是不是符合题意,如果‘c’在[0,len-1)区间内,判断一下它的下一个以及下下个是不是f,因为这个字符串是循环串,所以如果这个c是倒数第二个,判断一下最后一个和第一个字符是不是f
如果最后一个字符是c,判断一下第一个和第二个字符是不是f,如果是,sumc++; 不存在的时候就是sumf+sumc!=字符串的长度就行了
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int T,t=;
scanf("%d",&T);
while(T--)
{
string a;
cin>>a; int len=a.length();
int sumc=,sumf=,flag=;
for(int i = ;i < len;i++)
{
if(a[i]=='f')
sumf++;
else if(a[i]=='c')
{
if(a[i+]=='f'&&a[i+]=='f')
sumc++;
if(i==len-)
{
if(a[i+]=='f'&&a[]=='f')
sumc++;
}
if(i==len-)
{
if(a[]=='f'&&a[]=='f')
sumc++;
}
}
}
printf("Case #%d: ",t++);
if(sumc+sumf!=len)
printf("-1\n");
else
{
if(sumc==)
printf("%d\n",sumf+>>);
else
printf("%d\n",sumc);
}
}
return ;
}
Fang Fang HDU - 5455 (思维题)的更多相关文章
- hdu 4883 思维题
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 TIANKENG’s restaurant Time Limit: 2000/1000 MS (Ja ...
- hdu 5014 思维题/推理
http://acm.hdu.edu.cn/showproblem.php?pid=5014 从小数開始模拟找方法规律,然后推广,尤其敢猜敢尝试,错了一种思路继续猜-----这是一种非常重要的方法啊 ...
- Just Random HDU - 4790 思维题(打表找规律)分段求解
Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...
- HDU 6464 权值线段树 && HDU 6468 思维题
免费送气球 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 朋友HDU - 5963 (思维题) 三种方法
传送门 题目描述 输入 输出 样例输入 Sample Input 样例输出 Boys win! Girls win! Girls win! Boys win! Girls win! Boys win! ...
- hdu 5455 Fang Fang 坑题
Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...
- HDU - 5455 Fang Fang
Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence ...
- (字符串处理)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) ...
- HDU 5455:Fang Fang 查cff个数
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
随机推荐
- python-pexpect_02ssh
#!/usr/bin/env python """ This runs a command on a remote host using SSH. At the prom ...
- 打造atom成为golang开发神器
在我在Windows系统上开发的日子里.我使用IDE开发数年之久.比如Visual Basic IDE, Borland Delphi IDE, Visual C++ 和最后的Visual Studi ...
- poj 1741 楼教主男人八题之中的一个:树分治
http://poj.org/problem? id=1741 Description Give a tree with n vertices,each edge has a length(posit ...
- C++中的继承与虚函数各种概念
虚继承与一般继承 虚继承和一般的继承不同,一般的继承,在目前大多数的C++编译器实现的对象模型中,派生类对象会直接包含基类对象的字段.而虚继承的情况,派生类对象不会直接包含基类对象的字段,而是通过一个 ...
- POJ 3683 Priest John's Busiest Day (2-SAT+输出可行解)
题目地址:POJ 3683 第一次做须要输出可行解的题目. . .大体思路是先用强连通来推断是否有可行解,然后用逆序建图.用拓扑排序来进行染色.然后输出可行解. 详细思路见传送门 由于推断的时候少写了 ...
- singlefile.py
#! encoding=utf-8 import os import os.path AllFiles = {} MinSize = 8100 def OneDir( DirName ): if Di ...
- tiny4412 裸机程序 六、重定位代码到IRAM+0x8000【转】
本文转载自:http://blog.csdn.net/eshing/article/details/37115697 一.重定向 对于程序而言,我们需要理解两个概念,一是程序当前所处的地址,即程序在运 ...
- YTU 2750: 猜算式
2750: 猜算式 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 22 解决: 1 题目描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示 ...
- Kaggle "Microsoft Malware Classification Challenge"——就是沙箱恶意文件识别,有 Opcode n-gram特征 ASM文件图像纹理特征 还有基于图聚类方法
使用图聚类方法:Malware Classification using Graph Clustering 见 https://github.com/rahulp0491/Malware-Classi ...
- 这里有最全的C/C++入门到进阶书籍推荐,你需要嘛?
编程是操作性很强的一门知识,看书少不了,但只有学习和实践相结合才能起到很好的效果,一种学习方法是看视频->看书->研究书中例子->自己做些东西->交流->看书. 研究经典 ...