码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces A. Cakeminator 题解

时间:2014-07-22 23:03:35      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   

本题思路:

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

codeforces A. Cakeminator 题解

标签:style   blog   http   color   os   io   

原文地址:http://blog.csdn.net/kenden23/article/details/24810349

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!