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

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/veget_chicken/article/details/52346876
文章标签: 暴力
个人分类: 暴力
上一篇Launch of Collider
下一篇Vacations
想对作者说点什么? 我来说一句

csapp bomb lab

2018年03月20日 4KB 下载

没有更多推荐了,返回首页

关闭
关闭