zoukankan      html  css  js  c++  java
  • CF w3d2 B. Mystical Mosaic

    There is a rectangular grid of n rows of m initially-white cells each.

    Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows R i and a non-empty subset of columns C i are chosen. For each row r in R i and each column c in C i, the intersection of row r and column c is coloured black.

    There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) ( i < j) exists such that or , where denotes intersection of sets, and denotes the empty set.

    You are to determine whether a valid sequence of operations exists that produces a given final grid.

    Input

    The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.

    Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.

    Output

    If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).

    You can print each character in any case (upper or lower).

    Examples

    inputCopy
    5 8
    .#.#..#.
    .....#..
    .#.#..#.

    .#....#

    .....#..
    outputCopy
    Yes
    inputCopy
    5 5
    ..#..
    ..#..

    ..#..
    ..#..
    outputCopy
    No
    inputCopy
    5 9
    ........#

    ........

    ..##.#...
    .......#.
    ....#.#.#
    outputCopy
    No

    Note

    For the first example, the desired setup can be produced by 3 operations, as is shown below.

    For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.

    #include<bits/stdc++.h>
    using namespace std;
    bool ans=true;
    int n,m;
    char f[55][55];
    int judge(int x,int y)
    {
    	int flag=1;
    	for(int i=0;i<n;i++){
    		if(f[i][y]=='#'){
    			for(int j=0;j<m;j++)if(f[i][j]!=f[x][j])flag=0;
    		}
    	}
    	return flag;
    }
    int main()
    {
    	cin>>n>>m;
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++)cin>>f[i][j];
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			if(f[i][j]=='#'&&judge(i,j)==0){
    				ans=false;
    				break;
    			}
    		}
    		if(ans==false)break;
    	}
    	if(ans)cout<<"YES";
    	else cout<<"NO";
    	return 0;
    }
    
  • 相关阅读:
    指令到底是什么?机器码又是什么?
    汇编基础最后一篇--机器语言指令
    剑指OFFER----面试题34. 二叉树中和为某一值的路径
    剑指OFFER----面试题33. 二叉搜索树的后序遍历序列
    剑指OFFER----面试题32
    剑指OFFER----面试题31. 栈的压入、弹出序列
    剑指OFFER----面试题30. 包含min函数的栈
    剑指OFFER----面试题29. 顺时针打印矩阵
    剑指OFFER----面试题28. 对称的二叉树
    剑指OFFER----面试题27. 二叉树的镜像
  • 原文地址:https://www.cnblogs.com/LiangYC1021/p/12796472.html
Copyright © 2011-2022 走看看