CodeForces - 699B One Bomb

22人阅读 评论(0) 收藏 举报
分类:
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;
}

查看评论

【打CF,学算法——二星级】Codeforces 699B - One Bomb (技巧)

【CF简介】 题目链接:CF 699B 题面: B. One Bomb time limit per test 1 second memory ...
  • David_Jett
  • David_Jett
  • 2016-07-21 09:56:43
  • 1459

CodeForces 699B One Bomb

题目链接:http://codeforces.com/problemset/problem/699/B One Bomb time limit per test:1 secon...
  • Silenceneo
  • Silenceneo
  • 2016-07-20 20:27:54
  • 484

Codeforces 699B - One Bomb

B. One Bomb time limit per test1 second memory limit per test256 megabytes inputstandard input o...
  • nare123
  • nare123
  • 2016-07-20 13:48:40
  • 134

Codeforces699B One Bomb 暴力

You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell...
  • Megumin
  • Megumin
  • 2016-07-20 00:06:03
  • 193

Codeforces-699B One Bomb

You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell...
  • Snow_Me
  • Snow_Me
  • 2016-07-20 14:45:59
  • 253

【CF 699B】One Bomb(思维)

【CF 699B】One Bomb(思维) B. One Bomb time limit per test 1 second memory limi...
  • ChallengerRumble
  • ChallengerRumble
  • 2016-07-20 08:38:28
  • 565

Codeforces 699B One Bomb

题意: 你有一颗炸弹可以炸一行一列,问你如何放置炸弹能把所有的墙炸掉。 思路: 先计算墙的总个数和每一行每一列墙的个数,然后枚举每一个点,若满足该行墙的个数+该列墙的个数-1=墙的总个数那么这个...
  • w446506278
  • w446506278
  • 2016-07-20 10:08:25
  • 132

codeforces 699B One Bomb

Description You are given a description of a depot. It is a rectangular checkered field of n × m si...
  • fanesemyk
  • fanesemyk
  • 2016-07-20 10:15:06
  • 111

One Bomb CodeForces - 699B

B. One Bombtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputsta...
  • stanmae
  • stanmae
  • 2018-02-23 17:10:44
  • 21

codeforces 699B One Bomb

One Bomb time limit per test 1 second memory limit per test 256 megabytes input st...
  • zwj1452267376
  • zwj1452267376
  • 2016-07-20 10:31:49
  • 250
    个人资料
    持之以恒
    等级:
    访问量: 516
    积分: 151
    排名: 113万+
    最新评论