zoukankan      html  css  js  c++  java
  • The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏

    The Pilots Brothers' refrigerator
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 20304   Accepted: 7823   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
    /*
    由于变一个所在行与列都要变,所以对于是减号的转换到最后还是不变,也就是转换了偶数次,加号所在行与列一定进行转换,所以只需要统计加号所在行与列的
    转化次数,偶数不用变,奇数需要变,对于奇数和变一次的效果一样。所以次数就是奇数的次数。
    */
    
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <cctype>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    char s;
    int Arr[5][5];
    int main()
    {
        int sum=0;
        memset(Arr,0,sizeof(Arr));
        for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                cin>>s;
                if(s=='+')
                {
                    for(int k=0; k<4; k++)
                    {
                        Arr[i][k]++;
                        Arr[k][j]++;
                    }
                    Arr[i][j]--;
                }
            }
        }
        sum=0;
        for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                sum+=(Arr[i][j]%2);
            }
        }
        printf("%d
    ",sum);
        for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                if(Arr[i][j]%2)
                {
                    printf("%d %d
    ",i+1,j+1);
                }
            }
        }
        return 0;
    }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    关于正则表达式
    hashilib模块和hmac模块
    PyYAML模块和ConfigParser模块
    xml处理模块
    shutil模块(文件,文件夹,压缩包处理)
    十四、浏览器检测
    十三、BOM
    十二、匿名函数和闭包
    并发,并行,同步,异步的区别
    java中常见的类,接口,包,异常
  • 原文地址:https://www.cnblogs.com/juechen/p/4722029.html
Copyright © 2011-2022 走看看