One Bomb

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.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>

#define fi(x) for(int i=0;i<x;i++)
#define fj(x) for(int j=0;j<x;j++)
#define fk(x) for(int k=0;k<x;k++)
#define fid(x) for(int i=x-1;i>=0;i--)
#define fjd(x) for(int j=x-1;j>=0;j--)
#define fkd(x) for(int k=x-1;k>=0;k--)
#define fi1(x) for(int i=1;i<=x;i++)
#define fj1(x) for(int j=1;j<=x;j++)
#define fk1(x) for(int k=1;k<=x;k++)
#define fi1d(x) for(int i=x;i>0;i--)
#define fj1d(x) for(int j=x;j>0;j--)
#define fk1d(x) for(int k=x;k>0;k--)

using namespace std;

int x[1010], y[1010];
char s[1010][1010];

int main()
{
//freopen("in.txt", "r", stdin);
int n, m, num;
char temp;
cin >> n >> m;
num = 0;
fi(n)
fj(m) {
cin >> temp;
if (temp == '*')
{
x[i + 1]++;
y[j + 1]++;
num++;
s[i + 1][j + 1] = '*';
}
}
fi1(n)
fj1(m) {
int tn = x[i] + y[j];
if (s[i][j] == '*')
{
tn--;
}
if (tn == num)
{
cout << "YES\n" << i << ' ' << j << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}

【CF 699B】One Bomb（思维）

2016-07-20 08:38:28

csapp bomb lab

2018年03月20日 4KB 下载

B - One Bomb

2016-11-15 10:45:02

B. One Bomb（水题）

2017-05-06 08:41:17

699B - One Bomb

2016-07-20 08:02:55

B. One Bomb

2017-01-18 18:13:21

Codeforces #363 One Bomb

2016-07-20 12:02:59

Codeforces 699B One Bomb

2016-07-20 10:08:25

One Bomb CodeForces - 699B

2018-02-23 17:10:44

CodeForces-699B One Bomb 暴力搜索

2018-01-30 23:15:05