Codeforces Round 957 (Div. 3)-D. Test of Love
最编程
2024-07-12 07:04:46
...
We decided to test this love. ErnKor will have to swim across a river with a width of 1 meter and a length of ???? meters.Therefore, in total (that is, throughout the entire swim from 0 to ????+1) ErnKor can swim in the water for no more than ???? meters.
They are located at the 0 and ????+1 meters respectively. The river can be represented as ???? segments, each with a length of 1 meter. Each segment contains either a log 'L', a crocodile 'C', or just water 'W'. ErnKor can move as follows:
- If he is on the surface (i.e., on the bank or on a log), he can jump forward for no more than ???? (1≤m≤101≤????≤10) meters (he can jump on the bank, on a log, or in the water).
- If he is in the water, he can only swim to the next river segment (or to the bank if he is at the ????-th meter).
- ErnKor cannot land in a segment with a crocodile in any way.
p < n卡我很长时间,也是贪心思想,找到最近的L,动态更新
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
void solve(){
int n, m, k;
cin >> n >> m >> k;
string tmp;
cin >> tmp;
string s = " " + tmp;
int p = m;
int i = 1;
while(p <= n){
for(int j = i; j <= p && p <= n; j ++){
if(s[j] == 'L')
p = j + m;
}
if(p > n)
break;
while(p <= n && s[p] == 'W' && k >= 0){
k --;
p ++;
}
if(k < 0 || ( p <= n && s[p] == 'C')){
cout << "No" << endl;
return;
}else
i = p;
}
cout << "Yes" << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T--)
solve();
return 0;
}
上一篇: Memcached与Redis:缓存解决方案的较量与选择
下一篇: 路由器概述以及静态路由配置