bzoj1028: [JSOI2007]麻将

来源:互联网 发布:杭州淘宝客服招聘 编辑:程序博客网 时间:2024/04/28 11:04

链接

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

题解

  对付这种贪心题我真的是束手无策…..
  我是纯抄的题解….
  http://hzwer.com/3225.html

代码

//模拟#include <cstdio>#define maxn 10000using namespace std;int N, M, tong[maxn];bool check(){    int i, dui, tmp[maxn];    for(dui=1;dui<=N;dui++)    {        if(tong[dui]<2)continue;        for(i=1;i<=N;i++)tmp[i]=tong[i];tmp[dui]-=2;        for(i=1;i<=N;i++)        {            tmp[i]%=3;            while(tmp[i] and tmp[i+1] and tmp[i+2])tmp[i]--, tmp[i+1]--, tmp[i+2]--;        }        for(i=1;i<=N;i++)if(tmp[i])break;        if(i>N)return true;    }    return false;}int main(){    int i, add, x;    bool flag=0;    scanf("%d%d",&N,&M);    for(i=1;i<=3*M+1;i++)scanf("%d",&x),tong[x]++;    for(add=1;add<=N;add++)    {        tong[add]++;        if(check())        {            if(flag)printf(" ");            printf("%d",add), flag=1;        }        tong[add]--;    }    if(!flag)printf("NO");    return 0;}
0 0
原创粉丝点击