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;
    }
  • 相关阅读:
    37. VUE — webpack 基本使用
    36.VUE — 认识 Webpack 和 安装
    4. SpringBoot配置文件—YAML语法讲解
    3. IDEA 快速创建SpringBoot程序
    6. Maven 添加 镜像一些特性
    35. JS 模块化开发
    2. SPringBoot 解析HelloWorld 程序
    1. Maven 创建 SpringBoot项目 — HelloWorld — 我是踩了非常多的坑! 才写出来的 开学不顺 但是收获很多!!!
    34. VUE 的 编译作用域 以及 slot作用域插槽(获取组件作用域中的数据)
    【洛谷 3366】最小生成树_Kruskal
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3427158.html
Copyright © 2011-2022 走看看