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基础二
1.for循环后接else __author__ = "zhou" age_of_oldboy = 56 for i in range(3): guess_age = int(in ...
- 【GoLang】golang 闭包 closure 参数传递的蹊跷!
结论: 闭包函数可以直接引用外层代码定义的变量, 但是,注意,闭包函数里面引用的是变量的地址, 当goroutine被调度时,改地址的值才会被传递给goroutine 函数. 介绍 go的闭包是一个很 ...
- Markdown入门
http://www.jianshu.com/p/1e402922ee32/ 有道云笔记支持Markdown
- server2003中看不到网上邻居内容,其他电脑无法通过计算机名和IP访问本计算机(但网上邻居中可访问到)
现象1:server2003中看不到网上邻居内容,查看工作组计算机看到的是空列表, 现象2:其他电脑无法通过计算机名和IP访问本计算机(但网上邻居中可访问到) 访问提示:--Windows 200 ...
- PHP 面向对象
封装与不封装的区别: 未封装 时 外部随意更改数据 数据 不需要判定 就可以执行 外部直接操作数据 封装: 外部同样可以对数据更改,但需要 调用 类里面的 函数 外部间接操作数据 ...
- Power BI for Office 365(一)移动端应用
此篇来自于微软商业智能网站的官方博客团队发布的Power BI在线资料其中的一部分,完整版地址: http://office.microsoft.com/en-us/office365-sharepo ...
- 为什么在soui中加载JPG文件失败
在SOUI中解决解码器是一个独立的模块.不同的解码器决定了程序中能够加载什么样的图片类型.使用SComMgr来加载SOUI的模块时,debug模式下默认的图片解码器是imgdecoder-png.这个 ...
- Struts2 回顾总结
1.第一个Struts2入门案例 1.找jar包 Struts2-core xwork-core ognl javasist freemarker commons-lang commons-io co ...
- NOI 2010 海拔 ——平面图转对偶图
[题目分析] 可以知道,所有的海拔是0或1 最小割转最短路,就可以啦 SPFA被卡,只能换DIJ [代码] #include <cstdio> #include <cstring&g ...
- Android测试之 APK重签名方法
方法一:命令行重签名 D:\>keytool -helpkeytool 用法: -certreq [-v] [-protected] [-alias <别名>] [-sigalg & ...