2965 -- The Pilots Brothers' refrigerator
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 27893 | Accepted: 10802 | 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
Source
#include<iostream>
#include<stdio.h>
using namespace std;
char m[][];
int Count[][];
//判断状态
bool Check()
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(m[i][j] == '+') return ;//没有被全部打开
}
return ;
}
int getAns()
{//计算结果
int ans = ;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Count[i][j]% == )
{
Count[i][j] = ;
}else{
Count[i][j] = ;
ans++;
}
}
}
return ans;
}
int changeState()
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(m[i][j] == '+')//开关为关闭状态
{
m[i][j] = '-';
Count[i][j] += ;
for(int k = ;k<=;k++)
{
if(m[i][k] == '+') {m[i][k] = '-';}
else{m[i][k] = '+';}
}
for(int k=;k<=;k++)
{
if(m[k][j] == '+') {m[k][j] = '-';}
else{m[k][j] = '+';}
}
if(Check())
{//进行结果输出
return getAns();
}
}
}
if(Check() == ) return changeState();
} int main()
{
char c;
//初始化
while(true)
{
for(int i = ;i<=;i++)
for(int j=;j<=;j++)
Count[i][j] = ;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if((c = getchar()) == EOF) return ;
m[i][j] = c;
}
c = getchar();
} cout<<changeState()<<endl;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Count[i][j] == ) cout<<i<<" "<<j<<endl;
}
}
} return ;
}
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char m[][];
int Count[][];
//判断状态
bool Check()
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(m[i][j] == '+') return ;//没有被全部打开
}
return ;
}
int getAns()
{//计算结果
int ans = ;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Count[i][j]% == )
{
Count[i][j] = ;
}else{
Count[i][j] = ;
ans++;
}
}
}
return ans;
}
int main()
{
char c;
while(true)
{
memset(Count,,sizeof(Count));//初始化
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if((c = getchar()) == EOF) return ;
m[i][j] = c;
if(c == '+')
{
for(int k=;k<=;k++)
{
Count[k][j]++;
Count[i][k]++;
}
Count[i][j]--;
}
}
c = getchar();
}
///打印结果
cout<<getAns()<<endl;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Count[i][j] == ) cout<<i<<" "<<j<<endl;
}
}
} return ;
}
2965 -- The Pilots Brothers' refrigerator的更多相关文章
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- 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 暴力 难度: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 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(压位+bfs)
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
- poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...
- POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
随机推荐
- php 限制标题长度,将一个中文转换成一个字符
点击链接加入群[php/web 学习课堂]:https://jq.qq.com/?_wv=1027&k=5UJ9vEa 欢迎大家加入,一起讨论学习 玩这个功能的时候,我们要注意一点,我们是用中 ...
- qt打包发布
需要用到qt自带工具windeployqt.exe 安装 以qt 5.8.0为例 安装qt-opensource-windows-x86-mingw530-5.8.0.exe即可 构建Release版 ...
- vue项目前端限制页面长时间未操作超时退出到登录页
之前项目超时判断是后台根据token判断的,这样判断需要请求接口才能得到返回结果,这样就出现页面没有接口请求时还可以点击,有接口请求时才会退出 现在需要做到的效果是:页面超过30分钟未操作时,无论点击 ...
- explicit和implicit
explicit是C++中的一个关键字,只用于修饰只有一个参数的构造函数: class A{ explicit A(const T obj); }; 该关键字告诉编译器该类只能显式的转换,不能隐式(i ...
- MySQL安装步骤及环境变量配置
MySQL安装 MySQL下载地址:http://dev.mysql.com/downloads/installer/1:首先进入的是安装引导界面2:然后进入的是类型选择界面,这里有3个类型:Typi ...
- LintCode上的一道算法面试题: 数字的统计
说到数字的统计,小时候的数学课大家都应该有学过,但数字太多太复杂的,手动肯定耗时间不说还很容易出错.所以今天分享一下如何用程序来完成. Have you met this question in a ...
- Spark(一)wordcount
Spark(一)wordcount 一.新建一个scala项目 在maven中导入 <!-- https://mvnrepository.com/artifact/org.apache.spar ...
- PAT乙级1043
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805280074743808 题解 这次再次体会到题意理解的正确 ...
- linux异步传输支持
基于libusbx-1.0.18-rc1,libusbx现已重新merage到libusb.1. 初始化使用libusb_init初始化libusb,如果是单设备通信,ctx参数可以传NULL,表示使 ...
- jQuery.fn.extend() 函数详解
jQuery.fn.extend()函数用于为jQuery扩展一个或多个实例属性和方法(主要用于扩展方法). jQuery.fn是jQuery的原型对象,其extend()方法用于为jQuery的原型 ...