Alice’s Cube

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

Problem Description

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

3
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1
0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1

Sample Output
Case #1: 0
Case #2: 1
Case #3: more
 
Source
 
/**
题意:现在给出16盏灯的状态 然后每盏灯都有4个相连的灯
如果要改变当前灯的状态必须是它和它相邻的灯的状态不一样
要求最后转变的结果是1~8灭 9~16亮 并且操作步数<=3
如果满足要求 输出最小的步数,否则输出-1
做法:bfs() + 剪枝
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
#define INF 100000000
int step[( << ) + ];
int num[][] = {
{},
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , },
{, , , }
};
struct Node
{
int step;
int flag[];
};
void init()
{
for(int i = ; i <= ( << ) + ; i++)
{
step[i] = INF;
}
}
int eed = ( << ) - ( << );
int getnum(int aa[])
{
int sum = ;
for(int i = ; i >= ; i--)
{
sum = sum * + aa[i];
}
return sum;
}
Node Begin;
void bfs()
{
queue<Node>que;
Node now, tmp;
Begin.step = ;
que.push(Begin);
while(!que.empty())
{
now = que.front();
que.pop();
if(now.step >= ) {
continue;
}
int tt = getnum(now.flag);
if(tt == eed) {
break;
}
int numm = ;
for(int i = ; i <= ; i++)
{
if(now.flag[i] == ) {
numm++;
}
}
if(now.step + numm > ) {
continue;
}
for(int i = ; i <= ; i++)
{
for(int j = ; j < ; j++)
{
if(num[i][j] > i && now.flag[i] != now.flag[num[i][j]])
{
int ttt = now.flag[num[i][j]];
now.flag[num[i][j]] = now.flag[i];
now.flag[i] = ttt;
now.step ++;
int res = getnum(now.flag);
if(step[res] > now.step)
{
step[res] = now.step;
que.push(now);
}
now.step --;
ttt = now.flag[num[i][j]];
now.flag[num[i][j]] = now.flag[i] ;
now.flag[i] = ttt;
}
}
}
}
}
int main()
{
int T;
scanf("%d", &T);
int Case = ;
while(T--)
{
int tmp = ;
init();
for(int i = ; i <= ; i++)
{
scanf("%d", &Begin.flag[i]);
if(i <= && Begin.flag[i] == )
{
tmp++;
}
}
printf("Case #%d: ", Case++);
if(tmp > ) {
printf("more\n");
continue;
}
int st;
st = getnum(Begin.flag);
step[st] = ;
bfs();
if(step[eed] <= ) {
printf("%d\n", step[eed]);
}
else {
printf("more\n");
}
}
return ;
}

HDU-3320的更多相关文章

  1. hdu 3320 计算几何(三维图形几何变换)

    openGL Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  2. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  10. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. C#的Response.BinaryWrite图片乱码问题

    今天学习Response对象,该对象的有很多的输出方式,其中有一个binaryWrite可以输出图片,但是在输出图片一开始出现了乱码,后来通过百度得到解决: 代码: FileStream stream ...

  2. 总结const

    int b; const int  *a=&b; int const * a=&b; int * const a =&b; const int *const a=&b; ...

  3. Activiti工作流(二)——入门Demo及数据库

    上篇博客简单介绍了Activiti流程图的使用,这篇博客我们就根据这个流程图来完成这一个流程.  下图是Activiti的系统服务结构图,在后面的流程中,我们会用到其中的功能组件,如Repositor ...

  4. 【Linux】——实用命令

    [前言] Linux的命令可以分为文件存取.目录操作.进程管理.权限管理.磁盘操作等内容,大量的命令方便了用户进行更快捷更高效的工作.但有一点需要说明的是,如果不采用linux的命令,也可以完成相应的 ...

  5. Hibernate 映射文件基本概述

    映射文件描述了对象与数据库的关系,是Hibernate运行的核心文件之一,也是编写Hibernate的重点 映射文件是从java对象的角度去考虑的问题 基本的一个映射文件 <?xml versi ...

  6. JSP乱码问题

    在JSP中通过request对象获取请求参数时,如果遇到参数值为中文的情况,若不进行处理,获取到的参数值将是乱码.乱码情况分为以下两种: 1. 获取访问请求参数时乱码,采用如下方式解决. String ...

  7. SPOJ HIGH(生成树计数,高斯消元求行列式)

    HIGH - Highways no tags  In some countries building highways takes a lot of time... Maybe that's bec ...

  8. 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 解题报告

    P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...

  9. YUI Compressor是如何压缩JS代码的?

    YUI Compressor 压缩 JavaScript 的内容包括: 移除注释 移除额外的空格 细微优化 标识符替换(Identifier Replacement) YUI Compressor 包 ...

  10. 湖南大学第十四届ACM程序设计新生杯 E.Easy Problem

    E.Easy Problem Description: Zghh likes number, but he doesn't like writing problem description. So h ...