CodeForces 1992D Test of Love

题目链接:CodeForces 1992D【Test of Love】



思路

       从起点开始起跳,找出下一个木头的位置,若与当前位置的距离小于等于m,则可以直接跳过去,否则判断当前位置与下一个木头之间有没有鳄鱼,有鳄鱼则不能到达对岸,否则继续查找下一个木头,直到对岸。


代码

#include <functional>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#define ll long long
const int N = 500 + 10;

void solve(){
  int n, m, k;
  cin >> n >> m >> k;
  string s;
  cin >> s;
  s = "L" + s + "L";
  n += 2;
  int cur = 0, ans = 0;
  while (cur < n - 1) {
    int p = s.find("L", cur + 1);
    if (p == -1)
      break;
    if (p - cur <= m) {
      cur = p;
      continue;
    }
    cur += m;
    string tmp = s.substr(cur, p - cur);
    if (tmp != string(p - cur, 'W'))
      break;
    ans += p - cur;
      cur=p;
   }
   if (cur < n - 1 || ans > k)
     cout << "NO\n";
   else
     cout << "YES\n";
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
posted @ 2024-07-16 14:01  薛定谔的AC  阅读(18)  评论(0编辑  收藏  举报