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的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
随机推荐
- requests模块发送数据
通过json dumps发送 import requests import json def agent(): """ 执行命令采集硬件信息 将执行的信息发送给API : ...
- MySQL时间类型及获取、展示处理
MySQL时间格式 mysql所支持的日期时间类型有:DATETIME. TIMESTAMP.DATE.TIME.YEAR. 几种类型比较如下: 日期时间类型 占用空间 日期格式 最小值 最大值 零值 ...
- JavaSpring【四、Bean管理注解实现】
前面讲的Bean相关配置全部是使用xml配置文件或实现接口来实现的,接下来将比较常用的用法,使用注解实现bean的注入和管理 内容包括 ClassPath扫描与组件管理 类的自动检测与注册bean c ...
- Supervisor进程管理配置使用
Supervisor进程管理 在后台应用中,有时候程序进程会异常中止退出,如果没有一个守护进程去守护这个应用进程我们就需要及时发现并重启进程.如果每一个应用进程都写一个自己的守护进程难免会比较麻烦,而 ...
- PAT Basic 1059 C语言竞赛 (20 分)
C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 0.冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……). 1.排名为素数的学生将 ...
- jenkins"控制台输出"乱码问题解决
今天在搭建Jenkins环境时,安装完Tomcat.Jenkins.创建项目进行构建后,在查看控制台输出时,结果中文全部显示乱码.然后呢,就是漫长的解决历程,最终呢,解决乱码问题的时间终于超过了环境搭 ...
- freertos,串口接收数据后如何发送给任务
http://www.stmcu.org.cn/module/forum/thread-610230-1-1.html http://www.stmcu.org.cn/module/forum/thr ...
- 利用vue v-bind属性绑定bootstrap样式以及输出数据
自从知道了bootstrap,就被他简介,大气美观的样式吸引,即使在vue框架中,仍旧想使用,下面给出了vue适配版和原版的代码,以飨读者 数据输出部分 export default { data() ...
- 题解 [BZOJ1295][SCOI2009] 最长距离
题面 解析 \(n\)只有\(30\)可以直接枚举每个矩形, 判断他们的左上角到右下角或右上角到左上角的最短路是否小于\(T\). 最短路可以用\(dijkstra\). 一开始想用\(DP\)写最短 ...
- Sqlserver on linux 高可用集群搭建
一.环境准备 1 部署环境: 服务器数量:3台 Ip地址:192.168.1.191(主) 192.168.1.192(从) 192.168.1.193(从) 操作系统:CentOS Linux re ...