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 t,i,j,x,y,k,z,sum,q,flag,zz;
 7     char yj[1000001];
 8     scanf("%d",&t);
 9         k=1;
10         getchar();
11         while (t--)
12         {
13             sum=1;
14             gets(yj);
15             i=0;x=strlen(yj);
16             y=x-1;z=0;zz=0;
17             if (yj[0]==‘ ‘&&x==1)
18             {
19                 printf("Case #%d: 0\n",k++);
20                 continue;
21             }
22             while (yj[i]==‘f‘||yj[i]==‘ ‘)
23             {
24                 if (yj[i]==‘f‘)
25                    zz++;
26                 i++;
27             }
28             while (yj[y]==‘f‘||yj[y]==‘ ‘)
29             {
30                 if (yj[y]==‘f‘)
31                    z++;
32                 y--;
33             }
34             if (i==x)
35             {
36                  printf("Case #%d: %d\n",k++,(x+1)/2);
37                 continue;
38             }
39             if (i+z<2||yj[i]!=‘c‘)
40             {
41                 printf("Case #%d: -1\n",k++);
42                 continue;
43             }
44             q=i;flag=0;
45             for (j=i+1;j<x;j++)
46             {
47
48                 if (yj[j]==‘c‘)
49                 {
50                     sum++;
51                     if (j-q-1<2) flag=1;
52                     q=j;
53                 }
54                 if (yj[j]!=‘c‘&&yj[j]!=‘f‘&&yj[j]!=‘ ‘) flag=1;
55                 if (flag==1) break;
56
57             }
58             if (flag==1) printf("Case #%d: -1\n",k++);
59             else printf("Case #%d: %d\n",k++,sum);
60         }
61
62     return 0;
63 }
时间: 2024-08-06 08:24:27

hdu 5455 (2015沈阳网赛 简单题) Fang Fang的相关文章

ACM学习历程—HDU 5459 Jesus Is Here(递推)(2015沈阳网赛1010题)

Sample Input 9 5 6 7 8 113 1205 199312 199401 201314 Sample Output Case #1: 5 Case #2: 16 Case #3: 88 Case #4: 352 Case #5: 318505405 Case #6: 391786781 Case #7: 133875314 Case #8: 83347132 Case #9: 16520782 题目要求当前字符串序列中某项里cff前缀两两间差值的和. 假设已经纪录了cff前缀的

hdu 5459(2015沈阳网赛) Jesus Is Here

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果要模530600414. 很容易看出字符串的长度及c的个数都是由斐波那契数列构成的,得到最后结果是ans[i]=ans[i-1]+ans[i-2]+x,要求的就是x 假设第n项中字符'c'的个数为cn,字符'c'坐标之和为sn,字符串长度为ln 当形成第i个字符串的时候对于第i-1个字符串来说,这个

hdu 5443 (2015长春网赛G题 求区间最值)

求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 22 33 3 Sample Output1002344519999999999991 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm>

ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)

Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,an representing the size of the water source. Given a set of queries eac

hdu 5475 模拟计算器乘除 (2015上海网赛F题 线段树)

给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成1利用线段树的性质,对整个1~n的区间进行维护,每次输出sum[1]的值即可 Sample Input110 10000000001 22 11 21 102 32 41 61 71 122 7 Sample OutputCase #1:2122010164250484 1 # include <i

ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)

Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a com

ACM学习历程—HDU 5451 Best Solver(Fibonacci数列 &amp;&amp; 快速幂)(2015长春网赛1007题)

Problem Description The so-called best problem solver can easily solve this problem, with his/her childhood sweetheart. It is known that y=(5+2√6)^(1+2^x).For a given integer x (0≤x<2^32) and a given prime number M (M≤46337) , print [y]%M . ([y] mean

HDU 6205 2017沈阳网络赛 思维题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b[i]张)翻上,然后下一堆继续,直到没有足够的牌翻上,然后你可以获得当前已经操作过的堆的所有牌.最初你可以调整堆的顺序,把第一堆放到最后一堆(逆时针旋转),你可以重复这个操作,问你要重复多少次这个操作,才能获得最多的牌. 解法:先把这个序列复制一遍放在原来的序列后面.当i=n的时候结束就可以了,每次

hdu 5475(2015上海网赛) An easy problem

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5475 题意就是给X赋初值1,然后给Q个操作,每个操作对应一个整数M:如果操作是1则将X乘以对应的M,如果是2则除以第M次操作对应的M',求最后X的值对给定值取摸的结果, 直接暴力会爆long long,用数组存每一步的话 会超时,所以用线段树优化进行区间更新 1 #include<cstdio> 2 using namespace std; 3 typedef long long ll; 4 stru