zoukankan      html  css  js  c++  java
  • [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
    ", kase++);
    37             continue;
    38         }
    39         if(cnt == 0) {
    40             printf("Case #%d: %d
    ",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
    ", kase++);
    62         }
    63         else {
    64             printf("Case #%d: %d
    ", kase++, cnt);
    65         }
    66     }
    67 }
  • 相关阅读:
    用到了yii2 hasMany() 方法,一对多关联
    jquery操作select标签change事件
    Yii2如何批量添加数据
    [bzoj1497][NOI2006]最大获利
    [bzoj]2962序列操作
    洛谷 P1350 车的放置
    洛谷 P1142 轰炸
    初级数论练习题
    洛谷 P3795 钟氏映射
    洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
  • 原文地址:https://www.cnblogs.com/kirai/p/4822019.html
Copyright © 2011-2022 走看看