HDU 5455:Fang Fang 查cff个数
Fang Fang
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 945 Accepted Submission(s): 393
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.
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.
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 Saccording
to aforementioned rules. Repetitive strings should be counted repeatedly.
8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc
Case #1: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1HintShift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff".
水题,实际上就是查cff的个数。唯一的坑就是全部是f时要判断一下。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long test;
char a[1000005]; int main()
{
long long i, j, h, k, len, res, res_count;
int flag;
cin >> test;
for (i = 1; i <= test; i++)
{
cin >> a;
len = strlen(a);
flag = 1;
res = 0; for (h = 0; h < len; h++)
{
if (a[h] == 'c')
{
flag = 2;
if (a[(h + 1) % len] == 'f'&&a[(h + 2) % len] == 'f')
{
h = h + 2;
res++;
}
else
{
flag = 0;
break;
}
}
else if (a[h] == 'f')
{
continue;
}
else
{
flag = 0;
break;
}
}
if (flag == 0)
{
cout << "Case #" << i << ": " << -1 << endl;
}
else if (flag == 2)
{
cout << "Case #" << i << ": " << res << endl;
}
else
{
cout << "Case #" << i << ": " << (len+1)/2 << endl;
}
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5455:Fang Fang 查cff个数的更多相关文章
- HDU - 5455 Fang Fang
Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence ...
- 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) 题目思路: ...
- Ant Trip HDU - 3018(欧拉路的个数 + 并查集)
题意: Ant Tony和他的朋友们想游览蚂蚁国各地. 给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 保证这M条边都不同且不会存在同一点的自环边. 也就 ...
- More is better(hdu 1856 计算并查集集合中元素个数最多的集合)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
随机推荐
- ORACLE锁表问题
1.查询锁表的信息 select sess.sid,sess.serial#, lo.oracle_username,lo.os_user_name, ao.object_name,lo.locked ...
- vbox虚拟机vdi文件用VMware打开
转自:https://blog.51cto.com/dahui09/1863486 方法一: 使用VirtualBox 自带的VBoxManage来进行格式转换: 1.安装VBoxManage 2.使 ...
- 【转】stm32 IAP升级程序
一.什么是IAP,为什么要IAP IAP即为In Application Programming(在应用中编程),一般情况下,以STM32F10x系列芯片为主控制器的设备在出厂时就已经 ...
- 「Luogu P2568 GCD」
看到这是一道紫题还是和gcd有关的才点进来(毕竟数论只会gcd). 前置芝士 质数**(又称素数):因数只有1和本身,但是很特殊的1不是一个质数. gcd**:欧几里得算法,又称辗转相除法,可以在约为 ...
- 如何解决ajax跨域请求?
1.什么是跨域? a.域名不同 b.域名相同,端口不同 注:只有域名相同,端口相同时,才可以访问数据 可以使用jsonp解决ajax跨域请求的问题. 2.什么是jsonp? Jsonp其实就是一个跨域 ...
- Python 网络编程之网络协议(未完待续)
一:网络编程从两大架构开始 1.网络开发的两大架构 c/s 架构 : client server B/S 架构 : Brower server (1)bs 和 cs 架构之间的关系? (2)哪一种 ...
- NSString 常见数据类型转换:转NSInteger , NSDate(互转)
1. NSString转NSInteger, 转int (float, double类似 ) 1.1正常情况 , NSString所包含内容确能转化为int的类型 NSString *sNumber ...
- IdentityServer4专题之六:Resource Owner Password Credentials
实现代码: (1)IdentityServer4授权服务器代码: public static class Config { public static IEnumerable<Identity ...
- SciPy 教程
章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...
- Deepctr框架代码阅读
DeepCtr是一个简易的CTR模型框架,集成了深度学习流行的所有模型,适合学推荐系统模型的人参考. 我在参加比赛中用到了这个框架,但是效果一般,为了搞清楚原因从算法和框架两方面入手.在读代码的过程中 ...