Codeforces Round #192 (Div. 2) (329A)C.Purification

简介: Codeforces Round #192 (Div. 2) (329A)C.Purification

题意:


     在一个正常的点可以净化该行该列的所有细胞,判断是否可以净化所有的细胞,并且输出所选的点。


思路:


   如果可以的话,一定会选n个点。 先判断每一行是否有正常细胞,然后判断每一列是否有,如果都没有肯定不能净化,然后输出每一行或者每一列的第一个正常细胞的位置就好。

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int n ;
char map[110][110];
int main()
{
    cin>>n;
    int i , x[110] , y[110] , j;
    memset(x , 0 , sizeof(x));
    memset(y , 0 , sizeof(y));
    for(i = 0;i < n; i++ )
    {
        cin>>map[i];
        for(j = 0; j < n; j++)
        {
            if(map[i][j] == '.')
            {
                x[i] = 1;
                y[j] = 1;
            }
        }
    }
    int b = 0, c = 0;
    for(i = 0; i < n; i++)
    {
        if(x[i] == 0)  b = 1;
        if(y[i] == 0)  c = 1;
    }
    if(b&&c)
    {
        cout<<"-1"<<endl;
        return 0 ;
    }
    if(b == 0)
    {
        for(i = 0; i < n; i++)
            for(j = 0; j < n; j++)
            {
                if(map[i][j] == '.')
                {
                    cout<<i+1<<" "<<j+1<<endl;
                    break;
                }
            }
        return 0;
    }
    if(c == 0)
    {
        for(j = 0; j < n; j++)
            for(i = 0; i < n; i++)
            {
                if(map[i][j] == '.')
                {
                    cout<<i+1<<" "<<j+1<<endl;
                    break;
                }
            }
    }
    return 0;
}
目录
相关文章
|
8月前
|
机器学习/深度学习 人工智能 移动开发
.Codeforces Round 883 (Div. 3)
Codeforces Round 883 (Div. 3)
|
6月前
Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕。
24 0
|
6月前
|
人工智能 算法 BI
Codeforces Round #179 (Div. 2)A、B、C、D
我们每次加进来的点相当于k,首先需要进行一个双重循环找到k点和所有点之间的最短路径;然后就以k点位判断节点更新之前的k-1个点,时间复杂度降到O(n^3),而暴力解法每次都要进行floyd,时间复杂度为O(n^4);相比之下前述解法考虑到了floyd算法的性质,更好了运用了算法的内质。
31 0
|
7月前
Codeforces Round #742 (Div. 2)
Codeforces Round #742 (Div. 2)
27 0
|
8月前
|
机器学习/深度学习 Go
codeforces round 885 (div. 2)
codeforces round 885 (div. 2)
62 0
|
12月前
|
索引
Codeforces Round 817 (Div. 4)
Codeforces Round 817 (Div. 4)A~G题解
86 0
|
12月前
Codeforces Round 835 (Div. 4)
Codeforces Round 835 (Div. 4) A~F题解
87 0
|
人工智能
Codeforces Round #723 (Div. 2)B. I Hate 1111
Description You are given an integer x. Can you make x by summing up some number of 11,111,1111,11111,…? (You can use any number among them any number of times). For instance, 33=11+11+11 144=111+11+11+11
141 0
Codeforces Round #723 (Div. 2)B. I Hate 1111
|
人工智能 算法