[HDOJ5455]Fang Fang

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5455

先判断一发,然后记下c出现的位置(还要考虑转回到头部的情况),总之有c总会比单个f或者双f更少。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cmath>
 6
 7 using namespace std;
 8
 9 const int maxn = 100010;
10 const int INF = (1<<18);
11
12 char str[maxn];
13 int pos[maxn];
14
15 int main() {
16     // freopen("in", "r", stdin);
17     int T;
18     int kase = 1;
19     scanf("%d", &T);
20     while(T--) {
21         memset(pos, 0, sizeof(pos));
22         scanf("%s", str);
23         int len = strlen(str);
24         int cnt = 0;    //how c
25         int flag = 0;   //not
26         for(int i = 0; str[i]; i++) {
27             if(str[i] != ‘c‘ && str[i] != ‘f‘) {
28                 flag = 1;
29                 break;
30             }
31             if(str[i] == ‘c‘) {
32                 cnt++;
33             }
34         }
35         if(flag) {
36             printf("Case #%d: -1\n", kase++);
37             continue;
38         }
39         if(cnt == 0) {
40             printf("Case #%d: %d\n",kase++, len / 2 + len % 2);
41             continue;
42         }
43         int fir = INF;
44         int cur = 0;
45         for(int i = 0; str[i]; i++) {
46             if(str[i] == ‘c‘) {
47                 if(fir == INF) {
48                     fir = i;
49                 }
50                 pos[cur++] = i;
51             }
52         }
53         pos[cur++] = fir + len;   //circle
54         for(int i = 1; i < cur; i++) {
55             if(pos[i] - pos[i-1] <= 2) {
56                 flag = 1;
57                 break;
58             }
59         }
60         if(flag) {
61             printf("Case #%d: -1\n", kase++);
62         }
63         else {
64             printf("Case #%d: %d\n", kase++, cnt);
65         }
66     }
67 }
时间: 2024-10-19 06:55:18

[HDOJ5455]Fang Fang的相关文章

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",F

(字符串处理)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)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 233    Accepted Submission(s): 110 Problem Description Fang Fang says she wants to be

HDU - 5455 Fang Fang

Problem 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 > 2Write down a serenade as a lowercase string S in a circle,

Fang Fang

Problem 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 > 2Write down a serenade as a lowercase string S in a circle,

HDU5455 沈阳网络赛 Fang Fang

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意是 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 > 2Write down a serenade a

Fang Fang HDU - 5455 (思维题)

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", fo

HDU 5455 Fang Fang 水题,但题意描述有问题

题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路:判断多少个c,但是每个c之间必须有两个f,首尾的c也应判断首尾相连后两者之间的距离.坑点在与 1.给出的字符串中可能包含其它字符 2.严格按照gets()读入 3.若不含c,求有多少个f[2],若有多余补上一个f[1] 3.1.出题人神经病 #include<cstdio> #include<

hdu 5455 (2015沈阳网赛 简单题) Fang Fang

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不满足条件的,还有我被坑了的地方就是当输入很多f的时候,我尽然脑抽的 认为这是不满足条件的,注意这两点就行了,直接暴力 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int

Fang Fang hdu 5455

http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意:判断字符串最少符合题意的个数,它是一个环.若c前面有f,则把f的个数都加到后面去.还有一个坑点是,会有其他字母,不止有c,f. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <alg