hdu 5455 Fang Fang(2015 ACM/ICPC Asia Regional Shenyang Online)
来源:互联网 发布:淘宝店铺装修模板下载 编辑:程序博客网 时间:2024/06/16 18:54
点击打开链接
Fang Fang
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 531 Accepted Submission(s): 232
Problem Description
Fang Fang says she wants to be remembered.
I promise her. We define the sequenceF of strings.
F0 = ‘‘f",
F1 = ‘‘ff",
F2 = ‘‘cff",
Fn = Fn−1 + ‘‘f", for n > 2
Write down a serenade as a lowercase stringS in a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings inF , or nothing could be done but put her away in cold wilderness.
I promise her. We define the sequence
Write down a serenade as a lowercase string
Spell the serenade using the minimum number of strings in
Input
An positive integer T , indicating there are T test cases.
Following areT lines, each line contains an string S as introduced above.
The total length of strings for all test cases would not be larger than106 .
Following are
The total length of strings for all test cases would not be larger than
Output
The output contains exactly T lines.
For each test case, if one can not spell the serenade by using the strings inF , output −1 . Otherwise, output the minimum number of strings in F to split S according to aforementioned rules. Repetitive strings should be counted repeatedly.
For each test case, if one can not spell the serenade by using the strings in
Sample Input
8ffcfffcffcffcffcfffcffcffcffcfffffcffcfffcffcfffcffffcfffffcffcffc
Sample Output
Case #1: 3Case #2: 2Case #3: 2Case #4: -1Case #5: 2Case #6: 4Case #7: 1Case #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".
Source
2015 ACM/ICPC Asia Regional Shenyang Online
空行,,艾玛, 这题都快把我坑苦了,交流好几次都不对!!!
其实只要注意了这些东西也就没有问题了
解题思路:
首先将不是c 和 f 的字符扣去,输出-1;
先判断一下两个c之间的 f 数目,然后再判断开头和结尾就ok了
上代码吧:
/**2015 - 09 - 20 下午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;const int maxn = 1e6+5;const double eps = 1e-7;char str[maxn];int Init(){ int len, sum=0, flag=0; int x1, x2; len = strlen(str); for(int i=0; i<len; i++) { if(str[i] == 'c') { flag = 1; x1 = i; x2 = i; sum = 1; break; } } if(!flag) return (len+1)/2; for(int i=x1+1; i<len; i++) { if(str[i] == 'c') { if(i-x1 < 3) return -1; x1 = i; sum++; } } if(x2+len-x1-1 < 2) return -1; return sum;}int main(){ int T,cas; cin>>T; getchar(); for(cas=1; cas<=T; cas++) { gets(str); if(str[0] == '\n') printf("Case #%d: %d\n",cas, 0); else { bool ok = false; int len = strlen(str); for(int i=0; i<len; i++) { if(str[i]!='c' && str[i]!='f') { ok = true; break; } } if(ok) printf("Case #%d: %d\n",cas, -1); else printf("Case #%d: %d\n",cas, Init()); } } return 0;}
0 0
- hdu 5455 Fang Fang(2015 ACM/ICPC Asia Regional Shenyang Online)
- hdu 5455 Fang Fang 2015 ACM/ICPC Asia Regional Shenyang Online
- HDU 5455.Fang Fang【2015 ACM/ICPC Asia Regional Shenyang Online】【字符串处理】9月19
- HDU 5455 Fang Fang(关键就是c的个数)——2015 ACM/ICPC Asia Regional Shenyang Online
- hdu 5451(2015 ACM/ICPC Asia Regional Shenyang Online)
- HDU 5458 Stability (2015 ACM/ICPC Asia Regional Shenyang Online)
- 2015 ACM/ICPC Asia Regional Shenyang Online
- 2015 ACM/ICPC Asia Regional Shenyang Online
- 2015 ACM/ICPC Asia Regional Shenyang Online
- 2015 ACM/ICPC Asia Regional Shenyang Online
- 2015 ACM/ICPC Asia Regional Shenyang Online
- HDU-2017 ACM/ICPC Asia Regional Shenyang Online-签到题
- 2017 ACM/ICPC Asia Regional Shenyang Online 1001(hdu 6194)
- 2016 ACM/ICPC Asia Regional Shenyang Online
- 2017 ACM/ICPC Asia Regional Shenyang Online
- 2017 ACM/ICPC Asia Regional Shenyang Online
- 2017 ACM/ICPC Asia Regional Shenyang Online
- 2017 ACM/ICPC Asia Regional Shenyang Online
- objective-c 反射
- svm评价指标公式
- 5种服务器网络编程模型讲解
- 我 的 客 户 案 例
- “软件工程”
- hdu 5455 Fang Fang(2015 ACM/ICPC Asia Regional Shenyang Online)
- Leetcode67: First Bad Version
- Python中super的用法
- springsource tool suite下载地址分享
- tail -f log.txt命令的小技巧------观察日志log.txt的动态变化
- VIM配置
- servlet学习---第二天(GenericServlet、HttpServlet开发servler程序)
- java.lang.ClassNotFoundException: org.apache.cxf.transport.servlet.CXFServlet
- 访问wamp的PHPadmin时遇到Forbidden You don't have permission to access / on this server. You don't have per