The Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 20398   Accepted: 7857   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

本题主要是当需要改变某个+为-时,需要将他所在的行与所在的列都需要反转一次,如果反转两次相当与没反,所以每一反转的情况便可以的

最后判断%2时候的情况,==1便是需要反转的,否则不需要反转

‘#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int temp[4][4],ans[4][4];
char a[4][4];
int main(){
   memset(temp,0,sizeof(temp));
   memset(a,0,sizeof(a));
   memset(ans,0,sizeof(ans));
   for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
         scanf("%c",&a[i][j]);
         if(a[i][j]=='+')
         temp[i][j]=1;
         else
         temp[i][j]=0;
      }
      getchar();
   }
   for(int i=0;i<4;i++){
     for(int j=0;j<4;j++){
        if(temp[i][j]==1){
           for(int k=0;k<4;k++){
               ans[i][k]+=1;
               ans[k][j]+=1;
           }
           ans[i][j]-=1;

}
     }
   }
   int x[16],y[16];
   memset(x,0,sizeof(x));
  memset(y,0,sizeof(y));
   int count=0;
   for(int i=0;i<4;i++){
     for(int j=0;j<4;j++){
         if(ans[i][j]%2==1){
             x[count]=i;
             y[count]=j;
             count++;
         }
     }
    }
    cout<<count<<endl;
    for(int i=0;i<count;i++){
       cout<<x[i]+1<<" "<<y[i]+1<<endl;
    }

return 0;
}

poj2965枚举的更多相关文章

  1. 假期训练八(poj-2965递归+枚举,hdu-2149,poj-2368巴什博奕)

    题目一(poj-2965):传送门 思路:递归+枚举,遍历每一种情况,然后找出最小步骤的结果,与poj-1753类似. #include<iostream> #include<cst ...

  2. poj2965 The Pilots Brothers&#39; refrigerator(直接计算或枚举Enum+dfs)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://poj.org/problem? id=2965 ---- ...

  3. dfs+枚举,flip游戏的拓展POJ2965

    POJ 2965             The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: fo ...

  4. poj2965 【枚举】

    The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...

  5. POJ-2965 The Pilots Brothers' refrigerator---思维题

    题目链接: https://vjudge.net/problem/POJ-2965 题目大意: 一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列 ...

  6. poj2965 The Pilots Brothers' refrigerator —— 技巧性

    题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面 ...

  7. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  8. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  9. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

随机推荐

  1. [BZOJ 1483][HNOI 2009]梦幻补丁(有序表启发式合并)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1483 分析: 先将不同的颜色的出现位置从小到大用几条链表串起来,然后统计一下答案 对于 ...

  2. EntityFramework_MVC4中EF5 新手入门教程之三 ---3.排序、 筛选和分页

    在前面的教程你实施了一套基本的 CRUD 操作,为Student实体的 web 页.在本教程中,您将添加排序. 筛选和分页到 StudentsIndex的功能.您还将创建一个页面,并简单分组. 下面的 ...

  3. javascript去掉字符串前后空格

    使用场景 当我们进行一些页面编辑时,字符串前后的空格,通常是无效的.因此需要在获取信息时,进行过滤. 比如: 输入:[空格][空格]a[空格]b[空格][空格][空格] 得到:a[空格]b 代码如下: ...

  4. Linux CentOS6.5下编译安装MySQL 5.6.16【给力详细教程】

    一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake,从http://www.cmake ...

  5. javascript函数自调用

    1. 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. 2.  将函数用 “()”括起来, 后面再加一个“()” 3.  javascript函数的内置对象arguments对象,  它包 ...

  6. Active-MQ的安装

    (1)首先就是下载软件 wget http://archive.apache.org/dist/activemq/apache-activemq/5.9.0/apache-activemq-5.9.0 ...

  7. 最短路算法floyd

    内容: 对n个点(n<=450),已知他们的边,也就是相邻关系,求任意两个点的最短距离. 代码: for(int k=1; k<=n; k++)//k写在外面 for(int i=1; i ...

  8. [NOIP2010] 提高组 洛谷P1540 机器翻译

    题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件会先 ...

  9. C++ STL之stack

    因为总用vector,却忘记了有stack,今天用到栈顶的值才想起来,说起来stack很方便,也很容易用,看下边例子: #include<stack> #include<iostre ...

  10. tomcat7禁用catalina.out输出

    tomcat7中禁用catalina.out的输出,又可能很大. 直接修改catalina.sh文件的输出语句. 在文件中找到以下内容. if [ -z "$CATALINA_OUT&quo ...