# BZOJ 1028 [JSOI2007]麻将

## 1028: [JSOI2007]麻将

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 1270  Solved: 576
[Submit][Status][Discuss]

## Sample Input

9 4
1 1 2 2 3 3 5 5 5 7 8 8 8

6 7 9

## Source

 1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<algorithm>
5 #include<queue>
6 #include<cstring>
7 #define PAU putchar(' ')
8 #define ENT putchar('\n')
9 using namespace std;
10 const int maxn=10000+10,maxm=400+10;
11 int cnt,m,A[maxn],num[maxm],ans[maxn],total;
12 bool Judge(){
13     static int s[maxn],lim=cnt+2;
14     for(int i=1;i<=lim;i++)s[i]=num[i];
15     for(int i=1;i<=lim;i++){
16         if(s[i]<0) return false;
17         s[i]%=3;s[i+1]-=s[i];s[i+2]-=s[i];
18     }return true;
19 }
21     int x=0,sig=1;char ch=getchar();
22     while(!isdigit(ch)){if(ch=='-') sig=-1;ch=getchar();}
23     while(isdigit(ch)) x=10*x+ch-'0',ch=getchar();
24     return x*=sig;
25 }
26 inline void write(int x){
27     if(x==0){putchar('0');return;}if(x<0) putchar('-'),x=-x;
28     int len=0,buf[15];while(x) buf[len++]=x%10,x/=10;
29     for(int i=len-1;i>=0;i--) putchar(buf[i]+'0');return;
30 }
31 void init(){
32     cin>>cnt>>m;static int all=3*m+2;
34     for(int i=1;i<=cnt;i++){
35         A[all]=i;memset(num,0,sizeof(num));
36         for(int j=1;j<=all;j++)++num[A[j]];
37         for(int j=1;j<=cnt;j++)if(num[j]>=2){
38             num[j]-=2;if(Judge()){ans[++total]=i;break;}num[j]+=2;
39         }
40     }
41     if(!total){puts("NO");return;}
42     write(ans[1]);
43     for(int i=2;i<=total;i++)PAU,write(ans[i]);
44     return;
45 }
46 void work(){
47     return;
48 }
49 void print(){
50     return;
51 }
52 int main(){init();work();print();return 0;}

posted @ 2015-07-20 08:51  AI_Believer  阅读(269)  评论(0编辑  收藏  举报