'commit'
This commit is contained in:
42
TangDou/CSP-J/AcWingTraining/Iamthebest.cpp
Normal file
42
TangDou/CSP-J/AcWingTraining/Iamthebest.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 10010;
|
||||
int a[N];
|
||||
int st[N];
|
||||
int n, w;
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
cin >> w;
|
||||
if (n % w) {
|
||||
cout << "false" << endl;
|
||||
return 0;
|
||||
}
|
||||
sort(a + 1, a + 1 + n);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!st[i]) {
|
||||
st[i] = 1;
|
||||
int start = i + 1;
|
||||
int target = a[i] + 1;
|
||||
for (int j = 1; j < w; j++) {
|
||||
bool flag = false;
|
||||
for (int k = start; k <= n; k++) {
|
||||
if (!st[k] && a[k] == target) {
|
||||
st[k] = 1;
|
||||
flag = true;
|
||||
start = k + 1;
|
||||
target++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
cout << "false" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << "true" << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user