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 ...
随机推荐
- 学习bash——数据流重定向
一.概述 1. 数据流 定义:以规定顺序被读取一次的数据序列. 分类:标准输入(stdin).标准输出(stdout)和标准错误输出(stderr). 标准输出:指的是命令执行所回传的正确信息. 标准 ...
- 并发(三) CountDownLatch
CountDownLatch 和CyclicBarrier的区别是,CyclicBarrier可以循环使用,CountDownLatch不可以:CyclicBarrier可以有一个Runnable参数 ...
- WebSocket添加事件监听器(6)
WebSocket编程遵循异步编程模型;打开socket后,只需要等待事件发生,而不需要主动向服务器轮询,所以需要在WebSocket对象中添加回调函数来监听事件. WebSocket对象有三个事件: ...
- Div+Css中transparent制作奥运五环
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Ubuntu下Eclipse中运行Hadoop程序的参数问题
需要统一的参数: 当配置好eclipse中hadoop的程序后,几个参数需要统一一下: hadoop安装目录下/etc/core_site.xml中 fs.default.name的端口号一定要与ha ...
- ARC075 F.Mirrored
题目大意:给定D,询问有多少个数,它的翻转减去它本身等于D 题解做法很无脑,利用的是2^(L/2)的dfs,妥妥超时 于是找到了一种神奇的做法. #include <iostream> u ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- HDU3488:Tour(KM算法)
Tour Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- 马上给Meltdown和Spectre漏洞打补丁
元旦之后的第一个工作日可谓是惊喜不断,4号就传来了 Google Project Zero 等团队和个人报告的 Meltdown 和 Spectre 内核漏洞的消息,首先简单介绍一下这两个内核漏洞. ...
- canvas压缩图片变模糊问题
canvas 画图图片变模糊问题 问题描述 在使用 canvas 对图片进行编辑导出图片之后发现图片和原图相比变得模糊了 canvas 画图线条变粗 问题产生原因 该问题在 PC 下面并不会产生,原因 ...