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的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
随机推荐
- MUI 支付案例(支付宝/微信)
首先说明一下,本文借鉴了多位博主的文章,所以会看到很多一样的代码. 写这篇博客主要目的是为了便于后期查看(不好之处,敬请留言吐槽),案例经本人测试,是可以使用的. 先上效果图 前端HTML代码: &l ...
- MySQL时间类型及获取、展示处理
MySQL时间格式 mysql所支持的日期时间类型有:DATETIME. TIMESTAMP.DATE.TIME.YEAR. 几种类型比较如下: 日期时间类型 占用空间 日期格式 最小值 最大值 零值 ...
- 18.SSM整合_搭建开发环境
1.导入jar包 mybatis的Jar包 ehcache的Jar包 spring的 Jar包 mybatis 与 spring 整合Jar包 JSON的jar包 Jaskson的Jar包 Hiber ...
- c# MVC方式文件上传
MVC控制器中代码 index.cshtml <form action="/Home/Upload" method="post" enctype=&quo ...
- Xshell连接阿里云服务被拒绝
问题描述:突然的Xshell连接阿里云服务被拒绝了(如图)网上众多的方案都不行例如:https://www.cnblogs.com/wanglle/p/11416987.html(参考博文,本人这个问 ...
- Django form表单修改数据
form: #!/usr/bin/env python #coding:utf8 from django.forms import Form,ModelForm import models class ...
- Tenka1 Programmer Contest 2019 D - Three Colors
Three Colors 思路:dp 设sum为所有边的总和 不能组成三角形的情况:某条边长度>=ceil(sum/2),可以用dp求出这种情况的方案数,然后用总方案数减去就可以求出答案. 注意 ...
- okhttp拦截器之ConnectInterceptor解析
主流程分析: 继续分析okhttp的拦截器,继上次分析了CacheInterceptor缓存拦截器之后,接下来到连接拦截器啦,如下: 打开看一下它的javadoc: 而整个它的实现不长,如下: 也就是 ...
- 用代理服务加快brew下载速度。方法:curl
加快brew更新速度的方式:用代理 参考: https://www.zhihu.com/question/31360766常用的ss客户端都自带PAC模式的,比如ShadowsocksX-NG. 再次 ...
- FFmpeg常用命令学习笔记(二)录制命令
录制命令 1.FFmpeg录屏命令 ffmpeg -f avfoundation -i 1 -r 30 out.yuv -f:指定使用avfoundation采集数据 -i:指定从哪采集数据,它是一个 ...