Kenken Race

 题面:

有N个方块排成一排,从左到右编号为1,2,...,N。给你一个长度为N的字符串S. 和#。如果S的第i个字符是'#',则Square i包含一块岩石; 如果S的第i个字符是'.',则Square i是空的。一开始,Snuke站在Square A上,Fnuke站在Square B上。

你可以多次重复以下操作:

选择Snuke或Fnuke,让他向右跳一两个方块。目的地必须是其中一个方格,并且不得包含岩石或其他人。
你想重复这个操作,以便Snuke将站在Square C上,Fnuke将站在Square D上。
确定这是否可行。

 坑点:

处理c>d的情况

 思路:

首先, A 到 C中与 B 到 D中不能存在连续的两个障碍物。

其次,若 D<C ,需要额外满足 B到 D中存在至少一个空位两侧均为空位。

时间复杂度 O(N)。

 代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3  
 4 char s[300000];
 5 int n,a,b,c,d,f;
 6  
 7 int main() {
 8     scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
 9     scanf("%s", s + 1);
10     for (int i = c; i < d; i++) {
11         if (s[i] == '#' && s[i + 1] == '#') {
12             printf("No
");
13             return 0;
14         }
15     }
16     for (int i = a; i < c; i++) {
17         if (s[i] == '#' && s[i + 1] =='#') {
18             printf("No
");
19             return 0;
20         }
21     }
22     if (d < c) {
23         for (int i = b; i <= d; i++) {
24             if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
25                 f = 1;
26                 break;
27             }
28         }
29         if (f) {
30             printf("Yes
");
31         } else {
32             printf("No
");
33         }
34         return 0;
35     }
36     printf("Yes
");
37 }
View Code

 

原文地址:https://www.cnblogs.com/Accpted/p/11185659.html