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. SequoiaDB 系列之七 :源码分析之catalog节点

    这一篇紧接着上一篇SequoiaDB 系列之六 :源码分析之coord节点来讲 在上一篇中,分析了coord转发数据包到catalog节点(也有可能是data节点,视情况而定).这一次,我们继续分析上 ...

  2. 第十七章:jQuery类库

    javascript的核心API设计的很简单,但由于浏览器之间的不兼容性,导致客户端的API过于复杂.IE9的到来缓解了这种情况.然而使用javascript的框架或者工具类库,能简化通用操作,处理浏 ...

  3. “耐撕”团队2016.05.11站立会议

    1. 时间 18:15--18:35     共计20分钟 2. 人员 Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...

  4. java操作xm——添加、修改、删除、遍历

    package com.xml.zh; import javax.xml.parsers.*; import javax.xml.transform.Transformer; import javax ...

  5. ansible-1 的安装

    该文章摘自:http://my.oschina.net/firxiao/blog/343395,该文章制作笔记使用,不做他用,转载请注明原文链接出处 Ansible 默认是基于SSH协议进行通信的. ...

  6. 最短路算法floyd

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

  7. HDU-1754I Hate It 线段树区间最值

    这道题比较基本,就是用线段树维护区间最值,可以算是模板吧-.. I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768 ...

  8. poj 3070 矩阵快速幂模板

    题意:求fibonacci数列第n项 #include "iostream" #include "vector" #include "cstring& ...

  9. hihocoder 1154 Spring Outing

    传送门 #1154 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring ...

  10. python包的概念

    1 python程序由包(package).模块(module)和函数组成.包是由一系列模块组成的集合.模块是处理某一类问题的函数和类的集合. 2 包就是一个完成特定任务的工具箱. 3 包必须含有一个 ...