CodeForces - 699B One Bomb

B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a description of a depot. It is a rectangular checkered field of n × m size. 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.

Examples
input
Copy
3 4
.*..
....
.*..
output
Copy
YES
1 2
input
Copy
3 3
..*
.*.
*..
output
Copy
NO
input
Copy
6 5
..*..
..*..
*****
..*..
..*..
..*..
output
Copy
YES
3 3

思路:用两个数组统计横行,竖行*号的个数,遍历每个位置,如果在某个位置有与全部相等值就找到了,否则没有

#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
long long a[100050];
long long d[32];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int ans=1;
	for(int i=0;i<31;i++) {
		d[i]=ans;
		ans*=2;
	}
	long long maxn=0;
	for(int i=0;i<n;i++) {cin>>a[i];
	maxn=max(maxn,a[i]);
	}
	sort(a,a+n);
	long long ssd=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<31;j++)
		{
			int p=d[j]-a[i];
			if(p>maxn) break;
			if(p<0) continue;
			long long l=i+1,r=n-1;
			long long id=-1;
		    int tp1 = lower_bound(a+i+1, a+n, p)-a;
            int tp2 = upper_bound(a+i+1, a+n, p)-a;
             if(tp1 == n)
              continue;
            int tmp = tp2 - tp1;
              ssd += tmp;
		}
	}
	cout<<ssd<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37621623/article/details/79953477