• 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;
    }
  • 相关阅读:
    PHP.ini配置
    Ubuntu下启动/重启/停止apache服务器
    为 Ubuntu 上的 PHP 安装 APC,提升应用速度
    PHP文件上传并解决中文文件名乱码问题
    php目录结构
    PHP 服务器变量 $_SERVER
    PHP 编程的 5 个良好习惯
    PHP导入Excel和导出数据为Excel文件
    SharePoint 计算列公式(拷贝微软的SDK)
    SharePoint2010 文档评分(转)
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3427158.html
Copyright © 2020-2023  润新知