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个小开关 -+-- ---- ---- '+'表示开关是关着的,'-'表示开关是开着的,只有所有的开关全被打开,总开关才会被打开.现在有一种操作,只要改变某个开关, ...
随机推荐
- C#基本工具代码
1.下载Xlsx public static void TryToDisplayGeneratedFileXlsx(string writeFilePath, string fileName) { H ...
- 安装KB3132372补丁后,WIN10中IE内核加载flash崩溃
今天(2015年12月30日)突然很多人反馈在WIN10上IE内核的PC端应用崩溃.经过一番查找,最终定位到问题.WIN10今天发布了新的补丁KB3132372,64位系统更新该补丁后,打开IE内核的 ...
- 自己总结SVN必知点
1.只有添加或删除文件,才与xcodeproj文件有关 2.本地新建文件,为未知文件,符号为问号?,添加文件先add为A文件后,再commit 3.删除文件为叹号,右键删除为D,删除本 ...
- 这交互炸了:饿了么是怎么让Image变成详情页的
这交互炸了:饿了么是怎么让Image变成详情页的 晚上叫外卖,打开饿了么,发现推了一个版本,更新以后,点开了个鸡腿,哇,交互炫炸了. 本文同步自wing的地方酒馆 不过还是有槽点.我是无意中才发现可以 ...
- maven-replacer-plugin
今天多认识了下这个maven插件. 基本用法: <plugin> <groupId>com.google.code.maven-replacer-plugin</grou ...
- UltraEdit 注册机使用说明
请断开网络连接(或直接拔掉网线)后执行: 安装完成后,点击弹出界面的“注册”按钮,然后直接点击“激活”,此时UltraEdit检测到网络断开则弹出界面提示“脱机激活”,此时启动注册机,并将UltraE ...
- python中各种结构的复杂度
list The Average Case assumes parameters generated uniformly at random. Internally, a list is repres ...
- [leetcode] 29. divide two integers
这道题目一直不会做,因为要考虑的corner case 太多. 1. divisor equals 0. 2. dividend equals 0. 3. Is the result negative ...
- java线程池ThreadPoolExecutor使用简介
一.简介线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:ThreadPoolExecutor(int corePoolSize, int m ...
- Delphi 操作Flash D7~XE10都有 导入Activex控件 shockwave
http://www.cnblogs.com/devcjq/articles/2906224.html Flash是Macromedia公司出品的,用在互联网上动态的.可互动的shockwave.它的 ...