狡猾的兔子有n个洞,编号为1到n,兔子晚上只会在相邻的洞移动,猎人在白天检查其中一个洞。输入n及检查天数k,接下来输入k个整数,代表检查白天检查洞的编号。如果一定能抓住兔子,则输出yes,否则no.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k, t;
cin >> n >> k;
vector< int > days;
while (k--) {
cin >> t;
days.push_back(t - 1);
}
vector< int > hole(n, 1);
for (int i = 0; i < days.size(); ++i) {
vector< int > temp(n, 0);
for (int j = 0; j < n; ++j) {
if (hole[j] == 0) continue;
if (j == days[i]) continue;
else {
if (j == 0) {
if (j + 1 != days[i]) temp[j + 1] = 1;
} else if (j == n - 1) {
if (j - 1 != days[i]) temp[j - 1] = 1;
} else {
if (j + 1 != days[i]) temp[j + 1] = 1;
if (j - 1 != days[i]) temp[j - 1] = 1;
}
}
}
hole = temp;
}
int count = 0;
for (int i = 0; i < hole.size(); ++i) if (hole[i] && ++count) break;
if (count) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
}