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的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
随机推荐
- 服务框架 Pigeon 的设计与实现
1.服务框架Pigeon架构 监控系统 - CAT,负责调用链路分析.异常监控告警 配置中心 - Lion,负责一些开关配置读取 服务治理 - Governor 一个interface定义为一个服务, ...
- java EE,java Web中的400,404,405等各种错误介绍
4 请求失败4xx 4xx应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改请求的情况下重新尝试同一个请求.(例如,增加合适的认证信息).不过,同一个请求交给不同服务器也许就会成功. 4. ...
- shiro系列三、定义Realm
自定义realm: /** * 认证和授权 */ @Component public class UserRealm extends AuthorizingRealm { @Autowired pri ...
- 【Day3】2.re模块使用案例
课程目标 1.提取 2.匹配 3.替换 1.提取 import re ret = re.findall([正则表达式]) # 返回的类型是列表 2.匹配 import re ret = re.matc ...
- centos7下的/etc/rc.local自启动程序
在centos6中有一个/etc/rc.local的启动文件,只要把需要经常启动的程序添加到此文件下并执行source /etc/rc.local就可以实现开机启动了. 在centos7中不知道也是如 ...
- 我的第一个Node.js项目
Node.js的安装通常有两种方式:自己编译源代码和使用编译好的文件,我这里使用编译好的文件目前我的home目录下有刚下载来的node-v4.2.3-linux-x641.首先解压缩 tar xvf ...
- Matlab---绘制柱状图
Matlab---绘制柱状图 目录: hist()函数 histc( )函数 bar()函数 正文: 注意区分:频率.频数分布直方图. 一. hist()函数 hist():实 ...
- RxJava——响应式编程
自从06年开始,Rxandroid公司项目中陆续就开始使用它了,而它的基础是由Rxjava演变过来的,如今它也是越来越被广泛使用在商业项目中了,而做为"专业"的自己还是一直对它一知 ...
- 开放式最短路径优先OSPF
1.OSPF基本知识 OSPF作为基于链路状态的协议,解决了RIP在收敛慢,路由环路,可扩展性差等问题,还有以下优点: 采用组播方式发布报文,可以减少对其他不运行ospf路由器的影响 ospf直尺无类 ...
- C# MVC 视图 计算某一个列的总和
需求:在需要计算每一列的总和显示在最后一行 eg; AA BB CC 1 2 3 1 2 3 SUM 2 4 6 大概是酱紫 我用的是mvc Mo ...