hdu 5455 Fang Fang 坑题
Fang Fang
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5455
Description
Fang Fang says she wants to be remembered.
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.
Input
An positive integer T, 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.
Output
The output contains exactly T lines.
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
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
题意
f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2
给你一个字符串,问你最少有多少个f里面的东西组成
题解:
坑题,很简单的贪心,把c扔在前面就好
坑点:他可能输入不只是c,f,有可能输入乱七八糟的东西= =
比如caa
代码:
- //qscqesze
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- #include <stack>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define maxn 2000000 + 500
- #define mod 10007
- #define eps 1e-9
- int Num;
- char CH[];
- //const int inf=0x7fffffff; //нчоч╢С
- const int inf=0x3f3f3f3f;
- //**************************************************************************************
- string s;
- int main()
- {
- int t;scanf("%d",&t);
- for(int cas = ;cas<=t;cas++)
- {
- cin>>s;
- int flag = ;
- int st = ;
- int len = s.size();
- for(int i=;i<len;i++)
- if(s[i]!='c'&&s[i]!='f')
- flag=;
- if(flag==)
- {
- printf("Case #%d: -1\n",cas);
- continue;
- }
- for(int i=;i<len;i++)
- if(s[i]=='c')
- {
- flag = ;
- st = i;
- break;
- }
- if(!flag)
- {
- int ans = len/;
- if(len%==)ans++;
- printf("Case #%d: %d\n",cas,ans);
- continue;
- }
- int ans = ;
- flag = ;
- int temp = ;
- temp = ;
- for(int i=st;i<(st+len);i++)
- {
- if(s[i%len]=='c')
- {
- if(temp<)
- flag = ;
- temp = ;
- ans++;
- }
- else
- temp++;
- }
- if(temp<)
- flag = ;
- if(flag)
- printf("Case #%d: -1\n",cas);
- else
- printf("Case #%d: %d\n",cas,ans);
- }
- }
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 ...
- 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
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 5459(递推好题)
Jesus Is Here Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)To ...
- FZU- Problem 1147 Tiling,递推坑题,大数水过~~
Problem 1147 Tiling Time Limit: 1000 mSec Memory Limit : 32768 KB http://acm.fzu.edu.cn/problem.php? ...
- 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)
1952: [Sdoi2010]城市规划 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 73 Solved: 23[Submit][Status][ ...
- hdu 5455(字符串处理)
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total S ...
- String类面试坑题
1.面试坑题F:\SHJT\JavaWorkspace\JavaSE\workspace\day13ezra\src\cn\itcast\sh\classcode\BTStringLastIndexO ...
随机推荐
- storm - 基础概念整理
理论 Hadoop的出现虽然为大数据计算提供了一条捷径,但其仍然存在自身难以克服的缺点:实时性不足.Hadoop的一轮计算的启动需要较长时间,因此其满足不了对实时性有较高要求的场景. Storm由此应 ...
- Java数组你知多少?
下面我带大家一起加深一下对Java数组的认识: 1.理解数组 数组也是一种数据类型,本身就是一种引用类型,我们从它的初始化方法,通过关键字new去完成定义及初始化就可以知道. 数组的长度是不变的,一旦 ...
- Session简介
摘要:虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚session机制的本质,以至不能正确的应用这一技术.本文将详细讨论session的工作机制并且对在Java ...
- I.MX6 android 禁止低电量自动关机
/************************************************************************ * I.MX6 android 禁止低电量自动关机 ...
- CSS sprite 圆角——源代码
所需图片: corner ...
- InstallShield高级应用--检查是否安装ORACLE或SQL Server
InstallShield高级应用--检查是否安装ORACLE或SQL Server 实现原理:判断是否存在,是通过查找注册表是否含有相应标识来判断的. 注意:XP与WIN7系统注册表保存方式不一 ...
- HDU 5328 Problem Killer
题意:给一段序列,求连续的子序列中最长的等差数列或者等比数列的长度. 解法:O(n)的扫两遍一次判等差一次判等比就好了. 代码: #include<stdio.h> #include< ...
- 8、四大组件之三-ContentProvider
课程目标: 理解ContentProvider的作用及好处 认清ContentProvider与数据存储的关系 掌握ContentProvider对外提供的数据模型形式 能够编写ContentReso ...
- FZU 2214 Knapsack dp (转化背包)
就是一个背包裸题,由于物品的重量太大,开不了这么大的数组 所以转化一下,由于价值总和不大于5000,所以把价值看作重量,重量看作价值,那么就是同样的价值下,求一个最轻的重量 #include<c ...
- UVA1673 str2int(SAM)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51267 [题意] 给定n个字符串,计算所有忽略前导0的子串形成 ...