• HDOJ 3220 Alice’s Cube


    反向BFS+二进制记录
    Alice’s Cube

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1393    Accepted Submission(s): 407


    Problem Description
    HDOJ 3220 Alice’s Cube - qhn999 - 码代码的猿猿

    Alice has received a hypercube toy as her birthday present. This hypercube has 16 vertices, numbered from 1 to 16, as illustrated below. On every vertex, there is a light bulb that can be turned on or off. Initially, eight of the light bulbs are turned on and the other eight are turned off. You are allowed to switch the states of two adjacent light bulbs with different states (“on” to “off”, and “off” to “on”; specifically, swap their states) in one operation.

    Given the initial state of the lights, your task is to calculate the minimum number of steps needed to achieve the target state, in which the light bulbs on the sub cube (1,2,3,4)-(5,6,7,8) are turned off, and the rest of them are turned on.
     

    Input
    There are multiple test cases. The first line of the input contains an integer T, meaning the number of the test cases. There are about 13000 test cases in total.
    For each test case there are 16 numbers in a single line, the i-th number is 1 meaning the light of the i-th vertex on the picture is on, and otherwise it’s off.
     

    Output
    For every test cases output a number with case number meaning the minimum steps needed to achieve the goal. If the number is larger than 3, you should output “more”.
     

    Sample Input
    30 0 0 0 0 0 0 0 1 1 1 1 1 1 1 10 1 0 0 0 0 0 0 1 0 1 1 1 1 1 10 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1
     

    Sample Output
    Case #1: 0Case #2: 1Case #3: more
     

    Source
     

    Recommend
    zhuweicong
     


    #include <iostream>
    #include <cstring>
    #include <cmath>
    #include <queue>

    using namespace std;

    int vis[66000];

    char st[16]={'0','0','0','0','0','0','0','0','1','1','1','1','1','1','1','1'};

    int a[32]={1,3,2,1,10,2, 4, 1,3, 9, 9, 11,  6,14,6, 8, 5,13,5, 7, 13,15,5,7,  2,4,12,10,3,1,11,9};
    int b[32]={2,4,4,3,12,10,12,9,11,11,10,12,  8,16,14,16,7,15,13,15,14,16,6,8,  6,8,16,14,7,5,15,13};

    int bi(char *str)
    {
        int sum=0;
        for(int i=0;i<16;i++)
        {
            if(str=='1')
            {
                sum+=pow(2.,(double)(15-i));
            }
        }
        return sum;
    }

    void bfs(int k)
    {
        queue<int> q;
        q.push(k);
        while(!q.empty())
        {
            int st=q.front();
            q.pop();

            if(vis[st]>=3)  continue;

            for(int i=0;i<32;i++)
            {
                int j1=st&(1<<(a-1));
                int j2=st&(1<<(b-1));

                if(j1==j2)  continue;

                int temp=st;

                temp=temp^(1<<(a-1));
                temp=temp^(1<<(b-1));

                if(vis[temp]==-1)
                {
                    vis[temp]=vis[st]+1;
                    if(vis[temp]<3)  q.push(temp);
                }
            }
        }
    }

    int main()
    {
        memset(vis,-1,sizeof(vis));
        int k=bi(st);
        vis[k]=0;
        bfs(k);
    int n;
    cin>>n;
    for(int u=0;u<n;u++)
    {
        char str[16];
        for(int i=0;i<16;i++)
            cin>>str;
        int l=bi(str);

        int tot=vis[l];
        if(tot!=-1)
        {
            cout<<"Case #"<<u+1<<": "<<tot<<endl;
        }
        else
            cout<<"Case #"<<u+1<<": more"<<endl;
    }
        return 0;
    }


  • 相关阅读:
    Brighter3d无法渲染可导入REVIT渲染
    屏蔽优酷等视频网站片头广告
    REVIT机电管线支架族的创建
    如何显示链接的REVIT模型中的注释文字
    REVIT参数化自适应多边形拉伸
    REVIT族管理插件project family brower
    使用VMware虚拟磁盘管理工具调整磁盘大小
    硬件兼容性的陷阱,DrawIndexedPrimitiveUP的用法
    第二章 伤寒之意义(1)
    可变参数函数设计
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351094.html
Copyright © 2020-2023  润新知