zoukankan      html  css  js  c++  java
  • POJ 2965 The Pilots Brothers' refrigerator

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

    Northeastern Europe 2004, Western Subregion
     
     
     
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    int lock[10][10];
    int r[16],c[16];
    int flag,step;
    
    int isOpen(){
        int i,j;
        for(i=3;i<7;i++)
            for(j=3;j<7;j++)
                if(!lock[i][j])
                    return 0;
        return 1;
    }
    
    void flip(int row,int col){
        lock[row][col]=!lock[row][col];
        for(int i=3;i<7;i++)
            lock[i][col]=!lock[i][col];
        for(int j=3;j<7;j++)
            lock[row][j]=!lock[row][j];
    }
    
    void DFS(int row,int col,int deep){
        if(deep==step){
            flag=isOpen();
            return ;
        }
        if(flag || row==7)
            return ;
        r[deep]=row;
        c[deep]=col;
        flip(row,col);
        if(col<6)
            DFS(row,col+1,deep+1);
        else
            DFS(row+1,3,deep+1);
    
        flip(row,col);
        if(col<6)
            DFS(row,col+1,deep);
        else
            DFS(row+1,3,deep);
    }
    
    int main(){
    
        freopen("input.txt","r",stdin);
    
        char ch;
        memset(lock,0,sizeof(lock));
        for(int i=3;i<7;i++)
            for(int j=3;j<7;j++){
                cin>>ch;
                if(ch=='-')
                    lock[i][j]=1;
            }
        for(step=0;step<=16;step++){
            DFS(3,3,0);
            if(flag)
                break;
        }
        printf("%d\n",step);
        for(int i=0;i<step;i++)
            printf("%d %d\n",r[i]-2,c[i]-2);
        return 0;
    }
  • 相关阅读:
    测试用例编写(功能测试框架)
    OKR与KPI管理的区别与联系
    手机测试常见的BUG解析
    软件测试之BUG分析定位概述(QA如何分析定位BUG)【转自 https://blog.csdn.net/kaka1121/article/details/51538979】
    KPI、KPA、OKR三者的区别
    swagger api 文档框架
    Jmeter + Ant + Jenkins 接口/性能测试,持续集成环境搭建
    重建词汇精神家园
    记忆的本质
    attention机制七搞八搞
  • 原文地址:https://www.cnblogs.com/jackge/p/2944316.html
Copyright © 2011-2022 走看看