POJ2965
#include <stdio.h>
char map[4][4];
int map1[4][4];
int map2[4][4];
int num[16];
int min=1000,n;
int shu[20];
int shu1[20];
int len;
void bian(int x , int y)
{
for(int i=0;i<4;i++)
{
if(i!=y)
{
if(map2[x][i]==0)
map2[x][i]=1;
else
map2[x][i]=0;
}
if(map2[i][y]==0)
map2[i][y]=1;
else
map2[i][y]=0;
}
}
int safe()
{
int r=1;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(map2[i][j]==1)
{
r=0;
break;
}
}
if(r==0)
break;
}
return r;
}
void dfs(int step)
{
if(step==16)
{
n=0;
len=0;
int k=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
map2[i][j]=map1[i][j];
for(int i=0;i<16;i++)
{
if(num[i]==1)
{
bian(i/4,i%4);
shu[n]=i/4;
shu1[n]=i%4;
n++;
if(n>min)
return;
}
}
if(safe())
{
if(n<min)
{
min=n;
printf("%d\n",min);
for(int i=0;i<min;i++)
printf("%d %d\n",shu[i]+1,shu1[i]+1);
}
}
return ;
}
for(int i=0;i<2;i++)
{
num[step]=i;
dfs(step+1);
}
}
int main()
{
freopen("in.txt","r",stdin);
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='+')
map1[i][j]=1;
if(map[i][j]=='-')
map1[i][j]=0;
}
getchar();
}
dfs(0);
return 0;
}
POJ2965的更多相关文章
- POJ-2965 The Pilots Brothers' refrigerator---思维题
题目链接: https://vjudge.net/problem/POJ-2965 题目大意: 一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列 ...
- 假期训练八(poj-2965递归+枚举,hdu-2149,poj-2368巴什博奕)
题目一(poj-2965):传送门 思路:递归+枚举,遍历每一种情况,然后找出最小步骤的结果,与poj-1753类似. #include<iostream> #include<cst ...
- poj2965 The Pilots Brothers' refrigerator —— 技巧性
题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面 ...
- poj2965 The Pilots Brothers' refrigerator
题目链接:http://poj.org/problem?id=2965 分析:1.这道题和之前做的poj1753题目差不多,常规思路也差不多,但是除了要输出最少步数外,还要输出路径.做这道题的时候在怎 ...
- poj2965枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20398 ...
- POJ2965——The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...
- [POJ2965]The Pilots Brothers' refrigerator (搜索/位运算)
题意 游戏“The Pilots Brothers:跟随有条纹的大象”有一个玩家需要打开冰箱的任务. 冰箱门上有16个把手.每个手柄可以处于以下两种状态之一:打开或关闭.只有当所有把手都打开时,冰箱才 ...
- poj2965 【枚举】
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
- poj2965(位运算压缩+bfs+记忆路径)
题意:有个4*4的开关,里面有着16个小开关 -+-- ---- ---- '+'表示开关是关着的,'-'表示开关是开着的,只有所有的开关全被打开,总开关才会被打开.现在有一种操作,只要改变某个开关, ...
随机推荐
- python之路九
paramiko paramiko模块是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接 ssh执行命令: import paramikossh = pa ...
- mac os x 启用apache 和 php
Mac OS X 是自带 Apache 和 PHP 的,但默认情况下并没有开启,此文说明如何启用这两个服务,环境基于 Mac OS X 10.6 Snow Leopard. 启动 Apache 命令行 ...
- HTML5 声明兼容IE的写法(转载)
HTML5 声明兼容IE的写法(转载) 1 2 3 4 5 6 7 8 9 10 <!DOCTYPE html> <!--[if IE]> <meta http-eq ...
- string与wstring之间的转换
#include <string>std::string ws2s(const std::wstring& ws){ std::string curLocale = setl ...
- Android杂记:genymotion与eclipse报错问题
用eclipse启动genymotion时有时候会报 The connection to adb is down, and a severe error has occured. You must r ...
- c语言for循环
#include<stdio.h>#include<windows.h>#include <limits.h>#include <math.h>void ...
- 查找html中的某个事件
打开浏览器的调试功能,以chrome为例,按F12打开调试窗口,切换到Sources选项卡,最右边的Event Listener Breakpoints里勾选Mouse下的mouseover即可,当你 ...
- Oracle insert大量数据经验之谈(转)
在很多时候,我们会需要对一个表进行插入大量的数据,并且希望在尽可能短的时间内完成该工作,这里,和大家分享下我平时在做大量数据insert的一些经验. 前提:在做insert数据之前,如果是非生产环境, ...
- flume+kafka+hbase+ELK
一.架构方案如下图: 二.各个组件的安装方案如下: 1).zookeeper+kafka http://www.cnblogs.com/super-d2/p/4534323.html 2)hbase ...
- Python学习笔记(四)——编码和字符串
一.编码 1.编码类别: (1)ASCII码:127个字母被编码到计算机里,也就是大小写英文字母.数字和一些符号 (2)GB2312码:中国制定的用于加入中文汉字的编码 (3)Unicode:防止由于 ...