hdu 4490 Mad Veterinarian

来源:互联网 发布:linux route写入配置 编辑:程序博客网 时间:2024/06/04 20:01
91 40 1 01 1 11 1 01 0 1 1 3 0 02 1 0 0 2 0 03 2 3 4 5 1 24 1 1 2 3 1 12 40 3 40 0 50 0 31 2 0 0 0 0 52 2 0 0 0 0 43 1 2 3 0 0 14 1 2 3 0 0 23 60 1 11 0 11 1 01 1 2 3 0 1 02 1 2 3 0 1 13 1 2 4 1 0 04 2 0 0 0 2 05 2 3 4 0 1 06 0 1 0 2 3 44 62 0 00 2 00 0 21 1 2 3 0 1 02 1 2 3 1 1 13 1 0 5 1 0 14 5 2 0 1 1 05 0 2 3 0 1 16 1 0 1 6 0 75 10 1 11 1 01 0 11 1 2 3 0 0 16 60 0 11 0 00 1 01 1 2 3 1 0 12 1 2 3 5 0 13 4 2 3 5 3 14 0 2 6 5 3 05 1 2 1 1 3 06 3 3 3 5 0 47 11 1 11 0 11 1 01 1 2 3 0 1 08 10 2 53 0 31 1 01 0 2 3 5 0 09 20 1 01 0 10 0 21 1 1 4 2 0 02 2 0 0 0 0 2



以上是HDU的所有数据。。~~~嘎嘎嘎嘎



#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{    int an[4];    int step;    char op;    int set;}Q[1000005];void print(int x){    if(Q[x].op=='Z')return;    print(Q[x].set);    printf("%c",Q[x].op);}int C[4][4];bool vis[205][205][205];node tag;bool isok(node tt){    for(int i=1;i<=3;i++)    {        if(tt.an[i]!=tag.an[i])return false;    }    return true;}void debug(node t){    printf("----%d %d %d\n",t.an[1],t.an[2],t.an[3]);}void bfs(node t){    int head=0;    int tail=0;    Q[tail++]=t;    node w,e;    while(head<tail)    {        w=Q[head];        if(isok(w))        {            printf("%d ",w.step);            print(head);            return;        }        for(int k=1;k<=3;k++)        {            e=w;            if(e.an[k]<=0)continue;            e.an[k]--;            for(int cnt=1;cnt<=3;cnt++)            {                e.an[cnt]+=C[k][cnt];            }            if(e.an[1]>20 || e.an[2]>20 || e.an[3]>20)continue;            e.step++;            e.op=k+'A'-1;            e.set=head;            if(!vis[e.an[1]][e.an[2]][e.an[3]])            {                vis[e.an[1]][e.an[2]][e.an[3]]=true;                Q[tail++]=e;            }        }        for(int k=1;k<=3;k++)        {            e=w;            bool flag=false;            for(int cnt=1;cnt<=3;cnt++)   //先要判断能不能换  被坑了            {                e.an[cnt]-=C[k][cnt];                if(e.an[cnt]<0)flag=true;            }            e.an[k]++;            if(flag)continue;            //printf("k=%d   ",k);            //debug(e);            //getchar();            if(e.an[1]>20 || e.an[2]>20 || e.an[3]>20)continue;            e.step++;            e.op='a'+k-1;            e.set=head;            if(!vis[e.an[1]][e.an[2]][e.an[3]])            {                vis[e.an[1]][e.an[2]][e.an[3]]=true;                Q[tail++]=e;            }        }        head++;    }    printf("NO SOLUTION");}int main(){    int T;    //freopen("out.txt","w",stdout);    scanf("%d",&T);    while(T--)    {        int NUM,CASE;        scanf("%d%d",&NUM,&CASE);        for(int i=1;i<=3;i++)        {            for(int j=1;j<=3;j++)            scanf("%d",&C[i][j]);        }        int fuckingcase;        node t;        printf("%d %d\n",NUM,CASE);        for(int zenmezhemeduobianliang=1;zenmezhemeduobianliang<=CASE;zenmezhemeduobianliang++)//各种CASE的变量  法克        {            memset(vis,false,sizeof(vis));            scanf("%d",&fuckingcase);            for(int i=1;i<=3;i++)            scanf("%d",&t.an[i]);            for(int i=1;i<=3;i++)            scanf("%d",&tag.an[i]);            vis[t.an[1]][t.an[2]][t.an[3]]=true;            t.step=0;            t.set=-1;            t.op='Z';            printf("%d ",fuckingcase);            if(isok(t))            {                printf("0\n");                continue;            }            bfs(t);            printf("\n");        }    }    return 0;}/*21 23 0 00 0 00 0 01 1 0 0 3 0 02 1 0 0 1 0 02 20 3 40 0 50 0 31 2 0 0 0 0 52 2 0 0 0 0 4*/