博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2965——The Pilots Brothers' refrigerator(模拟)
阅读量:2344 次
发布时间:2019-05-10

本文共 1933 字,大约阅读时间需要 6 分钟。

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

给出4x4的把手,每次转动一个把手,其所在的列和行的把手都会被转动,求最少需要转动的把手至所有把手都打开,+号表示这个把手是关的

最主要的还是找规律吧,分享一个高效率的算法

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 100010#define Mod 10001using namespace std;int a[10][10];int main(){ char x; memset(a,0,sizeof(a)); for(int i=1;i<=4;++i) { for(int j=1;j<=4;++j) { cin>>x; if(x=='+') { for(int k=1;k<=4;++k) { a[i][k]++; a[k][j]++; } a[i][j]--; } } } int ans=0; for(int i=1;i<=4;++i) for(int j=1;j<=4;++j) if(a[i][j]%2) ans++; printf("%d\n",ans); for(int i=1;i<=4;++i) for(int j=1;j<=4;++j) if(a[i][j]%2) printf("%d %d\n",i,j); return 0;}

转载地址:http://qtcvb.baihongyu.com/

你可能感兴趣的文章
CPU输出数据的速度远远高于打印机的打印速度,为了解决这一矛盾,可采用()
查看>>
整型字符常量和字符字面量的区别 sizeof(char) 和 sizeof('a')
查看>>
表的主键特点中,说法不正确的是()
查看>>
用变量a给出下面的定义:一个有10个指针的数组,该指针指向一个函数,该函数有一个整形参数并返回一个整型数
查看>>
冯诺依曼工作方式的基本特点是____
查看>>
下列关于文件索引结构的叙述中,哪些是正确的?
查看>>
虚拟存储的容量受到下列哪一个因素的限制影响最大?
查看>>
Java程序优化的一些最佳实践
查看>>
《速度与激情8》中的信息安全技术
查看>>
超级互联网公司如何评估IT运营水平?
查看>>
多线程中start()与run()方法的区别
查看>>
使用My97DatePicker插件(现在基本使用前端框架自带的时间控件)
查看>>
Failed to convert from type java.lang.String to type java.util.Date for value解决办法
查看>>
MySQL数据库中的Date,DateTime和TimeStamp类型
查看>>
关于海量数据问题的解决方案
查看>>
给定一个数组,求前k小或者前k大
查看>>
程序员,你为什么值这么多钱?
查看>>
招聘面试的套路与原则
查看>>
技术与技术人员的价值
查看>>
对于垃圾回收相关的建议
查看>>