codeforces A. Cakeminator 题解

时间:2014-07-22 23:03:35   收藏:0   阅读:281

本题思路:

1 先扫描行,如果可以吃,就数吃了多少格,然后做好标志

2 扫描列,同样处理

扫描完就可以出答案了。

时间效率是O(n*m)了。算是暴力法

题目:

http://codeforces.com/problemset/problem/330/A



#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <iostream>
using namespace std;

void Cakeminator()
{
	unsigned row, col;
	cin>>row>>col;
	vector<string> cake(row);
	for (unsigned i = 0; i < row; i++)
	{
		cin>>cake[i];
	}
	int cakeCells = 0;
	for (unsigned i = 0; i < row; i++)
	{
		bool eatable = true;
		for (unsigned j = 0; j < col; j++)
		{
			if (‘S‘ == cake[i][j]) eatable = false;
		}
		if (eatable)
		{
			for (unsigned j = 0; j < col; j++)
			{
				if (‘.‘ == cake[i][j])
				{
					cake[i][j] = ‘E‘;
					cakeCells++;
				}
			}
		}
	}
	for (unsigned j = 0; j < col; j++)
	{
		bool eatable = true;
		for (unsigned i = 0; i < row; i++)
		{
			if (‘S‘ == cake[i][j]) eatable = false;
		}
		if (eatable)
		{
			for (unsigned i = 0; i < row; i++)
			{
				if (‘.‘ == cake[i][j])
				{
					cake[i][j] = ‘E‘;
					cakeCells++;
				}
			}
		}
	}
	cout<<cakeCells;
}




codeforces A. Cakeminator 题解,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!