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. 【集训试题】SiriusRen的卡牌 set

    题意概述: 给出N张卡牌,每张有三个属性a,b,c,同时给出所有属性可能的最大值A,B,C.对于一张卡牌,当这张卡牌至少有两个属性大于另外一张卡牌的对应两个属性的时候,认为这张卡牌更加优秀.现在问有多 ...

  2. int,long,long long类型的范围

    [内置类型] int      -2147483648-2147483647  //现在编译器的int型是32位的,以前为16位的范围是-32768~32767 unsigned  int   0-4 ...

  3. Week1 Team Homework #1 from Z.XML-项目选择思路--基于对曾经大作业项目的思考

    这两天试玩了一下去年学长的满分工程<shield star>游戏,再结合了一下他们团队的博客记录,有一种非常牛逼的感觉.具体对于这款游戏的一些思考和看法,毛大神已经说的很好了.因此,这里主 ...

  4. JavaWeb 基于Session的用户登陆注销实现

    通过Session来存储用户的部分登陆信息来验证用户是否在线,这应该时最容易实现的一种Web端方案,本文以SSM(Spring.SpringMVC.myBatis)框架为载体,来具体实现这套登陆系统. ...

  5. [Elasticsearch] 多字段搜索 (五) - 以字段为中心的查询

    以字段为中心的查询(Field-centric Queries) 上述提到的三个问题都来源于most_fields是以字段为中心(Field-centric),而不是以词条为中心(Term-centr ...

  6. JavaScript constructor 属性详解

    对象的constructor属性用于返回创建该对象的函数,也就是我们常说的构造函数. 在JavaScript中,每个具有原型的对象都会自动获得constructor属性.除了arguments.Enu ...

  7. ElasticSearch1.7.1拼音插件elasticsearch-analysis-pinyin-1.3.3使用介绍

    ElasticSearch拼音插件elasticsearch-analysis-pinyin使用介绍 https://my.oschina.net/xiaohui249/blog/214505 摘要: ...

  8. BZOJ day8

    好吧,, 补一天题解. 1001  狼抓兔子 妥妥的网络流啊,难度仅次于草地排水,边都给出来了.就是注意反向边也要有流量就行. 1007 水平可见直线 这个题按斜率排序(注意不是绝对值),然后将直线入 ...

  9. shell里的getopts

    By francis_hao    Jul 5,2017   getopts是shell的一个内置命令. 概述 getopts optstring name [args]OPTIND,OPTARG,O ...

  10. RTL2832U+R820T电视棒windows下安装sdr# 以及搭建ADS-B使用VirtualRadar看飞机的教程

    本文中提到的软件随后我会打包给出下载地址.这篇文章是我根据网上的教程和自己的经验修改的详细版本,为了方便入门新手.先来说说RTL2832U+R820T在windows下安装sdr#的方法.首先科普下s ...