zoukankan      html  css  js  c++  java
  • poj 3185 The Water Bowls (bfs 加未压缩)

    注意 标记hash[],不然会错(数据状态好像很多 ,所以要标记)
    http://poj.org/problem?id=3185
    #include<stdio.h>
    #include<string.h>
    #define N 1000000
    struct node
    {
        int num;
        int step;
    }p[N];
    
    bool hash[1048576];
    int d[20]={0xC0000,0xE0000,0x70000,0x38000,0x1C000,0xE000,0x7000,0x3800,0x1C00,
                 0xE00,0x700,0x380,0x1C0,0xE0,0x70,0x38,0x1C,0xE,0x7,0x3};
    
    int bfs(int num)
    {
        memset(hash,0,sizeof(hash));
        int head=0,tail=0,i;
        p[head].num=num;
        p[head].step=0;
        tail++;
        while(head<tail)
        {
            int k=p[head].num;
            if(k==0)return p[head].step;
            for(i=0;i<20;i++)
            {
                int  x=k^d[i];
                
                if(x==0)return p[head].step+1;
                else
                {
                    if(hash[x])continue;
                    hash[x]=1;
                    p[tail].num=x;
                    p[tail].step=p[head].step+1;
                    tail++;
                    if(tail==N-1)tail=0;
                }
            }
            head++;
    
        }
    }
    int main()
    {
        int a,f,i,j;
          int num=0;
    
         
        for(i=1;i<=20;i++)
        {
            scanf("%d",&a);
            num<<=1;
            num+=a;
        }
        int ans=bfs(num);
        printf("%d\n",ans);
    
    
    
    }
    

      

  • 相关阅读:
    2440中断
    2440内存管理
    printf不定参数
    时钟体系
    Uart串口
    链接脚本与重定位
    指令速记
    OpenOCD-JTAG调试
    ATPCS规则
    ARM三级流水线
  • 原文地址:https://www.cnblogs.com/acSzz/p/2438080.html
Copyright © 2011-2022 走看看