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个小开关 -+-- ---- ---- '+'表示开关是关着的,'-'表示开关是开着的,只有所有的开关全被打开,总开关才会被打开.现在有一种操作,只要改变某个开关, ...
随机推荐
- log4Net不能成功生成日志问题(关于配置错误)
log4Net不能成功生成日志问题(关于配置错误) 调试发现问题原因在于 Log4Net IsInfoEnabled 一直为 false,返回的对象中所有 IsXXX 一直为false,这个问题的原 ...
- CentOS7中禁用IPV6
helps from: https://linux.cn/article-4935-1.html vi /etc/sysctl.conf net.ipv6.conf.all.disable_ipv6 ...
- java23
1:多线程(理解) (1)多线程:一个应用程序有多条执行路径 进程:正在执行的应用程序 线程:进程的执行单元,执行路径 单线程:一个应用程序只有一条执行 ...
- Java基础之集合与泛型
话不多说,直接上图 1.Collection集合小结 注意: 凡是使用哈希表保存对象的容器,保存的对象在容器中都是唯一的,唯一性是通过被保存对象的hashCode和equals方法共同确定: 凡是使用 ...
- Tensorflow mlp二分类
只是简单demo, 可以看出tensorflow非常简洁,适合快速实验 import tensorflow as tf import numpy as np import melt_datas ...
- 【Android】命令行jarsigner签字和解决找不到证书链错误
1.签名失败 $jarsigner -verbose -keystore /Volumes/Study/resourcesLib/Qunero-achivements/AndroidApp/QuLor ...
- 【转】算法杂货铺——k均值聚类(K-means)
k均值聚类(K-means) 4.1.摘要 在前面的文章中,介绍了三种常见的分类算法.分类作为一种监督学习方法,要求必须事先明确知道各个类别的信息,并且断言所有待分类项都有一个类别与之对应.但是很多时 ...
- springMVC含文件上传调用ajax无法连接后台
springMVC在使用ajax进行后台传值的时候发现找不到对应的requestMapping(""),无法进入后台,在多次试验后确定是 MultipartFile对象与ajax冲 ...
- MySQL-多条件拼接语句
BEGIN "; SET @_where=""; THEN SET @_where= CONCAT(@_where," AND sourcedomain=\&q ...
- c语言完成宽带拨号
学校的网络每次开机都需要手动登陆,于是用c写了一个自动登陆的小程序... 程序功能超级简单...只是懒得每次都登陆... PS:代码功能具体没有测试...我自己用的是python #include & ...