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. 12.C#yield return和yield break及实际应用小例(六章6.2-6.4)

    晚上好,各位.今天结合书中所讲和MSDN所查,聊下yield关键字,它是我们简化迭代器的关键. 如果你在语句中使用了yield关键字,则意味着它在其中出现的方法.运算符或get访问器是迭代器,通过使用 ...

  2. [Aaronyang] 写给自己的WPF4.5 笔记[1布局]

    挫折时,要像大树一样,被砍了,还能再长:也要像杂草一样,虽让人践踏,但还能勇敢地活下去 --Aaronyang的博客(www.ayjs.net)-www.8mi.me =============时隔两 ...

  3. nginx 下 location 配置解释

    当我们在使用负载均衡和反向代理的时候 我们会考到虚拟主机下面有着个配置 现在我们看一下反向代理的location 下面的配置实例: server { listen 80 ;    监听的端口号 ser ...

  4. Oracle分页查询语句

    SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM (此处添加你要分页的表)) A WHERE ROWNUM <= 14000)WH ...

  5. BZOJ-1922 大陆争霸 多限制、分层图最短路 (堆+dijkstra)

    1922: [Sdoi2010]大陆争霸 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1154 Solved: 478 [Submit][Status ...

  6. 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth

    题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+N- ...

  7. redis安装步骤

    7.1创建业务安装用户 安装和配置Redis软件时,需要使用redis用户登录服务器进行相关操作,因此需要创建redis的业务安装用户组和redis的业务安装用户.此操作在主备机上同时进行. 创建用户 ...

  8. eclipse错误:Unable to read workbench state. Workbench UI layout will be reset.XML document structures

    Unable to read workbench state. Workbench UI layout will be reset.XML document structures must start ...

  9. 弱键(Weak Key, ACM/ICPC Seoul 2004, UVa1618)

    I think: 给出k(4≤k≤5000)个互不相同的整数组成的序列Ni,判断是否存在4个整数Np.Nq.Nr和Ns(1≤p<q<r<s≤k),使得Nq>Ns>Np&g ...

  10. 神器Alfred使用

    神器官网:http://www.alfredapp.com/ 许多人装好了之后就再也没有怎么使用过,这软神器, 一直不明白它为什么叫神器,最近研究了一下,真的是,很多东西我们没有好好利用 部分使用功能 ...