zoukankan      html  css  js  c++  java
  • H

    H - Purification
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

    The cleaning of all evil will awaken the door!

    Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.

    The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.

    You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.

    Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

    Input

    The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

    Output

    If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

    Sample Input

    Input
    3
    .E.
    E.E
    .E.
    Output
    1 1
    2 2
    3 3
    Input
    3
    EEE
    E..
    E.E
    Output
    -1
    Input
    5
    EE.EE
    E.EE.
    E...E
    .EE.E
    EE.EE
    Output
    3 3
    1 3
    2 2
    4 4
    5 3
     只要存在答案那么答案就是n!!!
    并且要么n行每行有"."
    或者n列每列有"."
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 300;
    
    char maze[200][200];
    struct Point
    {
        int x;
        int y;
    };
    vector<Point> p;
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int n;
        while(cin>>n)
        {
            p.clear();
            int r = 0;
            int c = 0;
            rep(i,0,n)
            {
                scanf("%s",maze[i]);
                rep(j,0,n)
                    if(maze[i][j] == '.')
                    {
                        r++;
                        p.push_back((Point){i+1,j+1});
                        break;
                    }
            }
            
            if(r == n)
            {
                rep(i,0,n)
                    cout<<p[i].x << " "<<p[i].y <<endl;
                continue;
            }
            p.clear();
            rep(i,0,n)
                rep(j,0,n)
                {
                    if(maze[j][i] == '.')
                    {
                        c++;
                        p.push_back((Point){j+1,i+1});
                        break;
                    }
                }
            if(c == n)
            {
                rep(i,0,n)
                    cout<<p[i].x << " "<<p[i].y <<endl;
                continue;
            }
            cout<<-1<<endl;
        }   
        return 0;
    }
  • 相关阅读:
    java 多个设备,锁定先后顺序
    使用个推的时候出现Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
    android 开发-设置控件/view的水平方向翻转
    IIS8中 出现ashx 401:未授权,uploadify上传文件失败
    No Launcher activity found!
    activiti工作流之Eclipse的Eclipse BPMN 2.0 Designer无法安装或者(安装后无法重复打开*.bpmn)
    android Ant 打包
    andorid 直接解压后的xml的解密
    获取当前运行的类名或者方法
    http断点下载客户端和服务端
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3427158.html
Copyright © 2011-2022 走看看