HDU-3320
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

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.
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.
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
/**
题意:现在给出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的更多相关文章
- hdu 3320 计算几何(三维图形几何变换)
openGL Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- 转 Using $.ajaxPrefilter() To Configure AJAX Requests In jQuery 1.5
Using $.ajaxPrefilter() To Configure AJAX Requests In jQuery 1.5 Posted February 18, 2011 at 6:29 PM ...
- Uuuuuunity
foreach http://blog.csdn.net/byondocean/article/details/6871881 yield http://www.cnblogs.com/CareyS ...
- HL7 2.6 解析(XML)
用途:检验化验(LIS)实验室设备数据交换解析. using System; using System.Collections.Generic; using System.Text; using Sy ...
- hdu 3231 Box Relations (拓扑排序)
Box Relations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- AGC018C Coins (set)
题目大意: 给出n个人,每个人手里都有xi个金牌,yi个银牌,ci个铜牌. 你需要选出X个人,拿走他们手里的金牌,选出Y个人,拿走他们手里的银牌,选出Z个人,拿走他们手里的铜牌 X+Y+Z = n.并 ...
- [LINUX]警告:检测到时钟错误。您的创建可能是不完整的。
[LINUX]警告:检测到时钟错误.您的创建可能是不完整的. 原因: 如果上一次编译时为20071001,你把系统时间改成20070901后再编译就会报这样的错误. 解决: 把时间 ...
- 从零开始实现Vue简单的Toast插件
在前端项目中,有时会需要通知.提示一些信息给用户,尤其是在后台系统中,操作的正确与否,都需要给与用户一些信息. 1. 实例 在Vue组件的methods内,调用如下代码 `this``.$toast( ...
- [NOI2010]能量采集 解题报告
[NOI2010]能量采集 题目描述 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. ...
- CDQZ 2017 游记
Day0: 提前放了一整天假,颓过去了.老吕让我去给B层的讲课,ppt还没做,只能在飞机上赶了QAQ.然后从上午到了衡水就一直在路上或者天上,到了晚上才到学校,然而ppt还是没有做完.还有,鄂尔多斯真 ...
- clear:both其实是有瑕疵的
在开发中,从美工MM给你Html代码中,肯定能经常看"<div style="clear:both;"></div>"这样的代码,但是你 ...