codeforces A. Cakeminator 题解

本题思路:

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

时间: 2024-10-11 13:41:09

codeforces A. Cakeminator 题解的相关文章

codeforces Flipping Game 题解

Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,?a2,?...,?an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1?≤?i?≤?j?≤?n) and flips all values 

codeforces The Wall - 题解

Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme o

codeforces Gravity Flip 题解

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th

codeforces A. TL 题解

Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m 

Codeforces Unlucky Ticket 题解

Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you th

codeforces A. k-String 题解

A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string

codeforces A. Array题解

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (?<?0). The product of all numbers in the secon

Codeforces Amusing Joke 题解

So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name i

codeforces Epic Game 题解

Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of nstones. The players take turns to m