# BZOJ 1028 麻将 枚举

https://www.lydsy.com/JudgeOnline/problem.php?id=1028

 1 #include<bits/stdc++.h>
2 #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
3 #define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数，会超时
4 #define Min(a, b) ((a) < (b) ? (a) : (b))
5 #define Mem(a) memset(a, 0, sizeof(a))
6 #define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
7 #define MID(l, r) ((l) + ((r) - (l)) / 2)
8 #define lson ((o)<<1)
9 #define rson ((o)<<1|1)
10 #define Accepted 0
12 using namespace std;
14 {
15     int x=0,f=1;char ch=getchar();
16     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
17     while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 typedef long long ll;
21 const int maxn = 2000 + 10;
22 const int MOD = 1000000007;//const引用更快，宏定义也更快
23 const int INF = 1e9 + 7;
24 const double eps = 1e-6;
25 int a[maxn];
26 int b[maxn];
27 int n, m;
28 bool judge()
29 {
30     memcpy(b, a, sizeof(a));
31     for(int i = 1; i <= n - 2; i++)
32     {
33         if(b[i] >= 3)b[i] %= 3;
34         if(b[i + 1] < b[i] || b[i + 2] < b[i])return false;
35         b[i + 1] -= b[i];
36         b[i + 2] -= b[i];
37         b[i] = 0;
38     }
39     if(b[n - 1] >= 3)b[n - 1] %= 3;
40     if(b[n] >= 3)b[n] %= 3;
41     if(b[n - 1] == 0 && b[n] == 0)return true;
42     return false;
43 }
44 bool ok()
45 {
46     for(int i = 1; i <= n; i++)if(a[i] >= 2)
47     {
48         a[i] -= 2;
49         if(judge())
50         {
51             a[i] += 2;
52             return true;
53         }
54         a[i] += 2;
55     }
56     return false;
57 }
58 int main()
59 {
60     scanf("%d%d", &n, &m);
61     int x;
62     vector<int>ans;
63     for(int i = 1; i <= 3 * m + 1; i++)scanf("%d", &x), a[x]++;
64     for(int i = 1; i <= n; i++)
65     {
66         a[i]++;
67         if(ok())ans.push_back(i);
68         a[i]--;
69     }
70     if(ans.size() == 0)puts("NO");
71     else
72     {
73         printf("%d", ans[0]);
74         for(int i = 1; i < ans.size(); i++)
75             printf(" %d", ans[i]);
76         puts("");
77     }
78     return Accepted;
79 }

posted @ 2018-09-29 12:51  _努力努力再努力x  阅读(157)  评论(0编辑  收藏  举报