The Pilots Brothers' refrigerator - poj 2965
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 20325 | Accepted: 7830 | Special Judge | ||
Description
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.
There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refrigerator is open only when all handles are open. The handles are represented as a matrix 4х4. You can change the state of a handle in any location [i, j] (1 ≤ i, j ≤ 4). However, this also changes states of all handles in row i and all handles in column j.
The task is to determine the minimum number of handle switching necessary to open the refrigerator.
Input
The input contains four lines. Each of the four lines contains four characters describing the initial state of appropriate handles. A symbol “+” means that the handle is in closed state, whereas the symbol “−” means “open”. At least one of the handles is initially closed.
Output
The first line of the input contains N – the minimum number of switching. The rest N lines describe switching sequence. Each of the lines contains a row number and a column number of the matrix separated by one or more spaces. If there are several solutions, you may give any one of them.
Sample Input
-+--
----
----
-+--
Sample Output
6
1 1
1 3
1 4
4 1
4 3
4 4
#include<stdio.h>
#include<string.h>
int main() {
int in[];
int tmp[];
int length=;
int size=length*length;
char temp;
//将输入变成0,1,开的为1,关的为0,放在数组in中
for(int i=;i<size;i++){
scanf("%c",&temp);
if(temp=='\n')
scanf("%c",&temp);
if(temp=='+')
in[i]=;
else
in[i]=;
}
// for(int i=0;i<size;i++){
// printf("%d \n",in[i]);
// }
//com数组存放的是开关的组合情况
int com[];
for(int i=;i<size+;i++){ for(int j=;j<i;j++){
com[j]=j;
}
int end=;
while(){
memcpy(tmp,in,size*sizeof(int));
//按照搜索到的组合情况对冰箱进行开关
for(int j=;j<i;j++){
int row=com[j]/;
int col=com[j]%;
for(int k=;k<length;k++){
tmp[row*length+k]=-tmp[row*length+k];
tmp[k*length+col]=-tmp[k*length+col];
}
tmp[row*length+col]=-tmp[row*length+col];
}
int zero=;
for(int j=;j<size;j++){
if(tmp[j]==){
zero+=;
}
}
// for(int k=0;k<4;k++){
// printf("%d\t",com[k]);
// }
// printf("\n");
// printf("sero is %d\n",zero);
// zero=size;
//判断是否找到答案
if(zero==size){
end=;
break;
}
//判断开关情况是i个的组合是否已经全部搜索完毕,是则搜索i+1个情况
if(com[]==size-i)
break;
//搜索下一个开关为i个的组合情况
for(int j=i-;j>=;j--){
if(com[j]!=size-(i-j)){
com[j]++;
for(int k=j+;k<i;k++)
com[k]=com[k-]+;
break;
} } }
//若找到结果,输出结果
if(end==){
printf("%d\n",i);
for(int j=;j<i;j++){
printf("%d %d\n",com[j]/+,com[j]%+);
}
}
} return ;
}
The Pilots Brothers' refrigerator - poj 2965的更多相关文章
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15136 ...
- POJ:2695-The Pilots Brothers' refrigerator
题目链接:http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limi ...
- The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20304 ...
- 2965 -- The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27893 ...
随机推荐
- [BZOJ2460][BJOI2011]元素(线性基)
2460: [BeiJing2011]元素 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2195 Solved: 1119[Submit][Sta ...
- [洛谷3808]【模板】AC自动机(简单版)
题目大意: 给定$n$个模式串$p(\sum|p_i|\le10^6)$和一个$t(|t|\le10^6)$,求在$t$中被匹配的$p$的个数. 思路: AC自动机模板题,注意$t$中一个字符可能对应 ...
- Jenkins忘记密码的修复方法(Windows/Linux)
在jenkins的安装目录下,找到config.xml配置文件,删除以下节点: <useSecurity>true</useSecurity> <authorizatio ...
- Vue.js 2.0源码解析之前端渲染篇
一.前言 Vue.js框架是目前比较火的MVVM框架之一,简单易上手的学习曲线,友好的官方文档,配套的构建工具,让Vue.js在2016大放异彩,大有赶超React之势.前不久Vue.js 2.0正式 ...
- UBIFS
转:http://www.armadeus.com/wiki/index.php?title=UBIFS This is a preliminary page dealing with the ins ...
- Unable to list target platforms. Please make sure the android sdk path is correct. See the Console for more details.
在android上发布遇到 androidSDK无法找到的问题 http://www.jianshu.com/p/fe4c334ee9fe
- github 丢失的本地提交
open git bash git reflog git reset xxxxxxx
- 什么是滤波器,滤波器是干嘛用的,IIR和FIR滤波器又是什么?(回答请简洁,别浪费大家时间)
信号频率筛选器,用于阻挡不需要的信号: 低通滤波用来阻挡某一频率之上的所有信号: 高通滤波用来阻挡某一频率之下的所有信号: 另外还有带通滤波器,带阻滤波器..... 个人理解,就像是个过滤沙子的筛子一 ...
- 【Hadoop】HDFS冗余数据块的自动删除
HDFS冗余数据块的自动删除 在日常维护hadoop集群的过程中发现这样一种情况: 某个节点由于网络故障或者DataNode进程死亡,被NameNode判定为死亡, HDFS马上自动开始数据块的容错拷 ...
- 软件测试技术---Web应用软件测试
从测试的角度看,Web应用软件的以下特点会导致Web应用软件的测试有别于其他软件的测试 1.基于无连接协议 2.内容驱动 3.开发周期短 4.演化频繁 5.安全性要求较高 6.美观性要求较高 Web应 ...