46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
vector<int> a; // 用来装都是什么牌
|
||
int n, w;
|
||
/*
|
||
9
|
||
1 2 3 6 2 3 4 7 8
|
||
3
|
||
|
||
9
|
||
1 2 3 6 2 3 4 7 9
|
||
3
|
||
*/
|
||
int main() {
|
||
cin >> n;
|
||
for (int i = 1; i <= n; i++) {
|
||
int x;
|
||
cin >> x;
|
||
a.push_back(x);
|
||
}
|
||
cin >> w;
|
||
|
||
// 特判
|
||
if (n % w) {
|
||
cout << "false" << endl;
|
||
return 0;
|
||
}
|
||
sort(a.begin(), a.end()); // 排序
|
||
|
||
while (a.size()) { // 如果数组中还有数据存在,就继续找
|
||
int x = a.front(); // 找到头是多少,比如获取到1
|
||
a.erase(a.begin()); // 把头删除
|
||
|
||
for (int i = 1; i < w; i++) {
|
||
x++; // 先确定要找的目标值
|
||
int idx = lower_bound(a.begin(), a.end(), x) - a.begin();
|
||
if (idx == a.size() || a[idx] != x) { // 没找到或者找到的不是目标值
|
||
cout << "false" << endl;
|
||
return 0;
|
||
}
|
||
a.erase(a.begin() + idx); // 删除掉
|
||
}
|
||
}
|
||
cout << "true" << endl;
|
||
return 0;
|
||
} |