zoukankan      html  css  js  c++  java
  • 训练赛(28)—— 计蒜客 45724 Jumping Frog

    题目链接https://vjudge.net/contest/386543#problem/C

    题目大意是有一只青蛙,每次可跳过d格(或更少),求从起点到终点至少需要跳几次。

    如果 i + d + 1 没有超过终点并且不是障碍物,就直接跳到 i + d + 1上。否则从i + d + 1

    开始,从后往前检查,找到遇到的第一个非障碍物,跳到那个位置上。如果找不到这样

    的位置,说明无法跳到终点。

    ac代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <string>
     6 #include <cmath>
     7 #include <vector>
     8 #include <queue>
     9 #include <map>
    10 using namespace std;
    11 typedef long long ll;
    12 
    13 int main()
    14 {
    15     int t;
    16     cin >> t;
    17     for (int Case = 1; Case <= t; Case++)
    18     {
    19         int c, d;
    20         string s;
    21         cin >> c >> d >> s;
    22         int cnt = 0;
    23         int flag = 0;
    24         for (int i = 0; i < c - 1;)
    25         {
    26 
    27             if (i + d + 1 < c && s[i + d + 1] == '.')
    28             {
    29                 cnt++;
    30                 i = i + d + 1;
    31             }
    32             else
    33             {
    34                 cnt++;
    35                 for (int j = i + d + 1; j > i; j--)
    36                 {
    37                     if (j < c && s[j] == '.')
    38                     {
    39                         i = j;
    40                         flag = 0;
    41                         break;
    42                     }
    43                     flag = 1;
    44                 }
    45             }
    46             if (flag) break;
    47         }
    48         cout << "Day #" << Case << endl;
    49         cout << c << " " << d << endl;
    50         cout << s << endl;
    51         if (flag) cout << "0" << endl;
    52         else cout << cnt << endl;
    53         cout << endl;
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    结对作业
    黄金分割点(第五周 c语言版)
    小程序(第四周)
    读程序作业(第三周)
    vs2013的安装及测试(第三周)
    学习进度条(第6周)
    努力爬的蜗牛
    学习日记1
    团队作业(七)
    团队作业(六)
  • 原文地址:https://www.cnblogs.com/zny0222/p/13418738.html
Copyright © 2011-2022 走看看