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个小开关 -+-- ---- ---- '+'表示开关是关着的,'-'表示开关是开着的,只有所有的开关全被打开,总开关才会被打开.现在有一种操作,只要改变某个开关, ...
随机推荐
- ecshop商品详情相册顺序调整
更改相册顺序为根据id升序: 找到/include/lib_goods.php 821行: 修改为: $sql = 'SELECT img_id, img_url, thumb_url, img_de ...
- Redis Sentinel机制与用法说明【转】
本文来自:https://segmentfault.com/a/1190000002680804 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Ma ...
- SQL入门语句之INSERT、UPDATE和DELETE
一.SQL入门语句之INSERT insert语句的功能是向数据库的某个表中插入一个新的数据行 1.根据对应的字段插入相对应的值 insert into table_name(字段A, 字段B, 字段 ...
- nginx 配置https upstream 跳转失败
访问首页没问题,但是在登录跳转重定向时域名被修改成upstream的名字 如果需要跳转的话会出现下面的情况: http://test-xxx-emove_pools/beehive/index ser ...
- [linux] grep awk sort uniq学习
grep的-A-B-选项详解grep能找出带有关键字的行,但是工作中有时需要找出该行前后的行,下面是解释1. grep -A1 keyword filename找出filename中带有keyword ...
- (一)安卓小app开发之基础环境搭建
一.准备工作: 1.下载Android Studio开发环境 https://dl.google.com/dl/android/studio/ide-zips/2.1.1.0/android-stud ...
- 分布式缓存技术memcached学习(三)——memcached内存管理机制
几个重要概念 Slab memcached通过slab机制进行内存的分配和回收,slab是一个内存块,它是memcached一次申请内存的最小单位,.在启动memcached的时候一般会使用参数-m指 ...
- BC一周年练习赛
Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262 ...
- CodeForces 514B
B. Han Solo and Lazer Gun time limit per test 1 second memory limit per test 256 megabytes input sta ...
- zookeeper心跳机制流程梳理
zookeeper心跳机制流程梳理 Processor链Chain protected void setupRequestProcessors() { RequestProcessor finalPr ...