关闭

One Bomb

标签: 暴力
37人阅读 评论(0) 收藏 举报
分类:
链接:

题目:

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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3173次
    • 积分:597
    • 等级:
    • 排名:千里之外
    • 原创:59篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    友情链接