BZOJ 1054 题解
1054: [HAOI2008]移动玩具
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 1888 Solved: 1035
[Submit][Status][Discuss]
Description
Input
Output
一个整数,所需要的最少移动次数。
Sample Input
0000
1110
0010
1010
0101
1010
0101
Sample Output
Solution
裸广搜,将状态用二进制数表示即可。
/**************************************************************
Problem: 1054
User: shadowland
Language: C++
Result: Accepted
Time:108 ms
Memory:16152 kb
****************************************************************/ #include "bits/stdc++.h" using namespace std;
struct Matrix { int M[ ][ ] , num ; } ;
const int maxN = ;
const int INF = ;
typedef long long QAQ ; Matrix Goal , Q[ maxN ] ;
int Find_Table[ maxN ] ;
bool vis[ ][ ] ;
int dx[ ] = { - , , , } , dy[ ] = { , , , - } ; QAQ ans , final ; int Condense ( Matrix tmp ) {
int ret = ;
for( int i= ; i<= ; ++i )
for( int j= ; j<= ; ++j )
ret = ( ret << ) + tmp.M[ i ][ j ] ;
return ret ;
} bool Judge( Matrix SHHHS ) {
int tmp = Condense( SHHHS ) ;
if ( tmp == ans ){ final = SHHHS.num ; return true ; }
bool key = true ;
if ( Find_Table[ tmp ] == true ) key = false ; if ( key == true ) Find_Table[ tmp ] = true ;
if ( key == true ) return true ;
else return false ;
} void BFS ( ) {
Find_Table[ Condense( Q[ ] ) ] = true ;
int head = , tail = ;
while( head <= tail ) {
Matrix t1 = Q[ head ] ;
for ( int i= ; i<= ; ++i ) {
for ( int j= ; j<= ; ++j ) {
if ( t1.M[ i ][ j ] == ) {
for ( int xi= ; xi< ; ++xi ) {
int xx = i + dx[ xi ] ;
int yy = j + dy[ xi ] ;
if( vis[ xx ][ yy ] ){
Matrix t2 = t1 ;
++ t2.num ;
t2.M[ xx ][ yy ] = t1.M[ i ][ j ] ;
t2.M[ i ][ j ] = t1.M[ xx ][ yy ] ;
if( Judge( t2 ) ) Q[ ++ tail ] = t2 ;
if( final ) return ;
}
}
}
}
}
++ head ;
}
return;
} int main( ) { memset ( vis , true , sizeof ( vis ) ) ; for ( int i= ; i<= ; ++i ) {
for ( int j= ; j<= ; ++j ) {
char ch = getchar ( ) ;
Q[ ].M[ i ][ j ] = ch - '' ;
}
getchar ( ) ;
} getchar ( ) ; for ( int i= ; i<= ; ++i ){
for ( int j= ; j<= ; ++j ){
char ch = getchar ( ) ;
Goal.M[ i ][ j ] = ch - '' ;
}
getchar ( ) ;
} ans = Condense( Goal );
if ( ans == Condense ( Q[ ] ) ) { cout << '' << endl ; goto End ;}
BFS ( ) ;
printf( "%lld\n" , final );
End :
return ;
}
2016-10-14 23:41:11
(完)
BZOJ 1054 题解的更多相关文章
- BZOJ 1054: [HAOI2008]移动玩具(bfs)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1054 题解: 将每一种状态十六位压成二进制,然后bfs..不解释.. p.s.注意特判初始 ...
- BZOJ 1054 [HAOI2008]移动玩具
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1388 Solved: 764[Submit][Statu ...
- BZOJ 3732 题解
3732: Network Description 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N. 图中有M条边 (1 <= M <= 30,000) ...
- BZOJ 1054 广搜
1054: [HAOI2008]移动玩具 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动 时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩 ...
- bzoj 1054: [HAOI2008]移动玩具 bfs
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 在 ...
- bzoj 1054 移动玩具
题目连接 http://www.lydsy.com/JudgeOnline/problem.php?id=1054 移动玩具 Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想 ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
- [HAOI 2005][BZOJ 1054] 移动玩具
先贴一波题面 1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2288 Solved: 1270 Descr ...
- bzoj 2669 题解(状压dp+搜索+容斥原理)
这题太难了...看了30篇题解才整明白到底咋回事... 核心思想:状压dp+搜索+容斥 首先我们分析一下,对于一个4*7的棋盘,低点的个数至多只有8个(可以数一数) 这样的话,我们可以进行一个状压,把 ...
随机推荐
- linux cpuInfo
转自:http://blog.csdn.net/lgstudyvc/article/details/7889364 /proc/cpuinfo文件分析 在Linux系统中,提供了proc文件系统显 ...
- 【转载】Python编写简易木马程序
转载来自: http://drops.wooyun.org/papers/4751?utm_source=tuicool 使用Python编写一个具有键盘记录.截屏以及通信功能的简易木马. 首先准备好 ...
- 6-05使用SQL语句删除数据
删除数据语法: DELETE FROM 表名 WHERE 删除条件. TRUNCATE TABLE 表名. --[1]基本删除,省略WHERE条件,将删除表中的所有数据 DELETE FROM ...
- PHP实现上一篇、下一篇
//php实现上一篇.下一篇 获取当前浏览文章id $id = isset($_GET[ ? intval($_GET['id']) : ""; 下一篇文章 $query = my ...
- [SQL]oracle 的to_char、to_number、to_date用法
关键字: oracle 的to_char.to_number.to_date用法 TO_CHAR 是把日期或数字转换为字符串TO_DATE 是把字符串转换为数据库中得日期类型转换函数TO_NUMBER ...
- CRC校验(转)
CRC即循环冗余校验码(Cyclic Redundancy Check[1] ):是数据通信领域中最常用的一种差错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据 ...
- android如何实现文件按时间先后顺序排列显示
<span style="font-size:18px;">File[] files =parentFile.listFiles(fileFilter);//通过fil ...
- 图解LoadAverage(负载)
图解LoadAverage(负载) http://www.habadog.com/2015/02/27/what-is-load-average/ 一.什么是Load Average 系统负载(S ...
- Loadrunner中参数化实战(9)-Unique+Once
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Once 设置迭代4次Action 结果如下:
- loadrunner获取本机的机器名称