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 > 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.

  题意大概就是给你一个首尾相接的cf串, 求出他最少有几个Fn串组成, 比如cffcfff最少由两个串组成, 1:cff 2:cfff, 观察答案我们感觉到这个题似乎与c有关, 因此对于每一个c我们求出其后面f的个数再加以判断,另外还需考虑没有c的情况, 此题还有一个坑点就是输入不保证全是由c f组成,

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
char str[1000000 + 100];

int main() {
    int T;
    scanf("%d", &T);
    int kase = 0;
    while(T--) {
        scanf("%s", str);
        int len = strlen(str);
        bool qita = false;

        for(int i=0; i<len&&!qita; i++){
            if(str[i]!=‘c‘&&str[i]!=‘f‘) qita=true;
        }
        if(qita) {
            printf("Case #%d: -1\n", ++kase);
            continue;
        }
        int geshu = 0;
        for(int i=0; i<len&&str[i]!=‘c‘; geshu++, i++);   //由于是首尾相接, 我们求出开头f的个数
//        printf("geshu = %d\n", geshu);
        bool flog = true;
        int res = 0;
        for(int i=len-1; i>=0; i--){
            if(str[i]==‘c‘){
                res++;
                if(geshu < 2) {          //此时的geshu就是当前的c后面f的个数
                    flog = false;
                    break;
                }
                geshu = -1;
            }
            geshu++;
        }

        if(res == 0){                     //处理没有c的情况
            geshu /= 2;                   //没有c的时候我们求出的f个数是实际个数的两倍
            if(geshu%2==0) res = geshu/2;
            else res = geshu/2+1;
        }
        if(flog) {
            printf("Case #%d: %d\n", ++kase, res);
        }else{
            printf("Case #%d: -1\n", ++kase);
        }
    }
    return 0;
}
时间: 2024-08-29 01:35:26

HDU5455 沈阳网络赛 Fang Fang的相关文章

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

2019ACM-ICPC沈阳网络赛-C-Dawn-K&#39;s water(完全背包模板题)

Dawn-K's water  1000ms 262144K Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package. On this day, Dawn-K came to the supermarket

2019ACM-ICPC沈阳网络赛-K-Guanguan&#39;s Happy water(思维+暴力)

Guanguan's Happy water 4000ms 262144K Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerat

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

2015年ACM沈阳网络赛(准备做掉4道:)

Traversal Best Solver Minimum Cut Dividing This Product Excited Database Fang Fang Matches Puzzle Game Hold Your Hand Stability Jesus Is Here Poker Largest Point Manors

沈阳网络赛G-Spare Tire【容斥】

17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an?1??an?2?

HDU 6205 2017沈阳网络赛 思维题

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

HDU 6200 2017沈阳网络赛 树上区间更新,求和

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边就是对于u,v必须通过这条边才能到达. 解法:一个很简单的想法,搞出图上的一颗树,然后剩下的边当成询问点队加到更新点集,每加入一个更新点对,直接把u,v区间的值置为0即可,查询就直接区间求和,可以直接树剖来维护,简单暴力,读入挂卡过.还有1个log的做法,可以用LCT维护(这个没写,口胡的) #in

2016沈阳网络赛 Barricade

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description The empire is under attack again. The general of empire is planning to defend his castle. The land can be seen as N towns and M roads, a