CodeForces-699B One Bomb 暴力搜索

                                               One Bomb

题目描述:

You are given a description of a depot. It is a rectangular checkered field of n × msize. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").

You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.

You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.

The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.

Output

If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).

Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.

Example
Input
3 4
.*..
....
.*..
Output
YES
1 2
Input
3 3
..*
.*.
*..
Output
NO
Input
6 5
..*..
..*..
*****
..*..
..*..
..*..
Output
YES
3 3


题目意思是在一个矩阵中找到合适的点,满足所有 * 都在这个点的行和列上。

虽然是 1000 X 1000 , 暴力有点悬,但是还是可以过的( 30ms ....... 不敢相信 )。

输入矩阵的时候做一下统计,x数组记录所有行上的墙的数目,y 数组记录列上的墙的数目。

同时,累计墙的总数。

枚举矩阵每一个点,如果这个点的行和列上的墙(*)总数恰好等于总墙数,说明这个点符合条件, 

炸弹放在这里可以炸掉所有的墙。

而且,可以先判断一下数组中是否有墙 ? cnt == 0 , 直接输出一个,不用搜索了。

输出注意下标从 1 开始。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std ;
char text[1001][1001] ;
int x[1001] , y[1001] ;

int main(){
	int n , m  , cnt = 0 ;
	scanf( "%d%d" , &n , &m ) ;
	for( int i = 0 ; i < n ; ++i ){
		scanf( "%s" , text[i] ) ;
		for( int j = 0 ; j < m ; ++j )
			if( text[i][j] == '*' )
				x[i]++ , y[j]++ , cnt++ ;  // cnt 统计墙的个数
	}
	if( cnt == 0 ){ cout << "YES" << endl << "1 1" << endl ; return 0 ; }
	for( int i = 0 ; i < n ; ++i )
		for( int j = 0 ; j < m ; ++j ){
			int ans = text[i][j] == '*' ? x[i]+y[j]-1 : x[i]+y[j] ;
			if( ans == cnt ){
				cout << "YES" << endl ;  cout << i+1 << " " << j+1 << endl ;
				return 0 ;
			}
		}
	cout << "NO" << endl ;
	return 0 ;
}

这题,我一开始不想暴力的,想通过统计 x , y 数组,找出 x 数组和 y 数组最大的值所在的行和列,交叉点是符合条件的,那样就不用搜索1000*1000的矩阵了。 可惜一直没过,卡在第 10 组数据上,可惜上 codeforces 看不到完整的第十组数据。以后过了,再补上吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值