# bzoj1028 [JSOI2007]麻将

### Solution

#include<bits/stdc++.h>
using namespace std;

int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
inline void write(int x) { if (x > 10) write(x / 10); putchar(x % 10 + '0'); }

#define N 1001
#define rep(ii, aa, bb) for (int ii = aa; ii <= bb; ii++)
#define fech(i, x) for (int i = 0; i < x.size(); i++)
#define ll long long

int n, m;
int bur[N], tmp[N];
vector<int> ans;

bool check() {
rep(i, 1, n) tmp[i] = bur[i];
rep(i, 1, n) while (tmp[i]) {
if (tmp[i] >= 3) { tmp[i] -= 3; continue; }
if (i <= n - 2 && tmp[i + 1] && tmp[i + 2]) { --tmp[i], --tmp[i + 1], --tmp[i + 2]; continue; }
return 0;
}
return 1;
}

int main() {
cin >> n >> m;
rep(i, 1, 3 * m + 1) bur[read()]++;
rep(i, 1, n) {
bur[i]++;
bool flag = 0;
rep(j, 1, n)
if (bur[j] >= 2) {
bur[j] -= 2; flag = check(); bur[j] += 2;
if (flag) break;
}
if (flag) ans.push_back(i);
--bur[i];
}
if (!ans.size()) puts("NO");
else {
sort(ans.begin(), ans.end()); unique(ans.begin(), ans.end());
fech(i, ans) {
if(i && ans[i] <= ans[i - 1]) break;
write(ans[i]), putchar(' ');
}
}
return 0;
}

posted @ 2018-02-05 09:25  aziint  阅读(175)  评论(0编辑  收藏  举报