bzoj 1028: [JSOI2007]麻將

來源:互聯網
上載者:User

標籤:

暴力枚舉+貪心

 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<queue> 7 #include<map> 8 #include<cmath> 9 #define M 10000910 #define ll long long11 #define Mo 99824435312 #define pa pair<int,int>13 using namespace std;14 ll read()15 {16     char ch=getchar();17     ll x=0,f=1;18     for(;ch<‘0‘||ch>‘9‘;ch=getchar())19       if(ch==‘-‘)20         f=-1;21     for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar())22       x=x*10+ch-‘0‘;23     return x*f;24 }25 int a[M],shu[M],n,m,ans[M];26 bool pan()27 {28     for(int i=1;i<=n;i++)29       a[i]=shu[i];30     for(int i=1;i<=n-2;i++)31       {32         if(a[i]<0)33           return 0;34         a[i]=a[i]%3;35         a[i+1]-=a[i];36         a[i+2]-=a[i];37       }38     if(a[n-1]%3||a[n]%3)39       return 0;40     return 1;41 }42 int main()43 {44     n=read();45     m=read();46     for(int i=1;i<=3*m+1;i++)47       {48         int a1=read();49         shu[a1]++;50       }51     for(int i=1;i<=n;i++)52       {53         shu[i]++;54         for(int j=1;j<=n;j++)55           {56             if(shu[j]<2)57               continue;58             shu[j]-=2;59             if(pan())60               {61                 ans[++ans[0]]=i;62                 shu[j]+=2;63                 break;64               }65             shu[j]+=2;66           }67         shu[i]--;68       }69     for(int i=1;i<ans[0];i++)70       printf("%d ",ans[i]);71     if(!ans[0])72       printf("NO\n");73     else74       printf("%d\n",ans[ans[0]]);75     return 0;76 }

 

bzoj 1028: [JSOI2007]麻將

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.