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;
    }
  • 相关阅读:
    函数的随机梯度下降(固定函数与自定义函数随机梯度下降)
    常见六种随机变量分布可视化
    基于beautifulSoup进行电影网站排名的获取与格式化输出
    基于numpy实现矩阵计算器
    中文论文-LaTex模板
    论文阅读:Deformable ConvNets v2
    darknet loss可视化软件
    《为什么精英都是时间控》读书总结
    Window下Latex加速编译方法以及西农毕设论文模板推荐
    时间加数字问题
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3427158.html
Copyright © 2011-2022 走看看