Cakeminator (标记一下就好了)

You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows:

The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.

Please output the maximum number of cake cells that the cakeminator can eat.

Input

The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains ccharacters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these:

  • '.' character denotes a cake cell with no evil strawberry;
  • 'S' character denotes a cake cell with an evil strawberry.

Output

Output the maximum number of cake cells that the cakeminator can eat.

Examples

Input

3 4
S...
....
..S.

Output

8

题意:

就是有一个n*m的蛋糕,有几个坏草莓,你吃的时候要避开这些坏草莓,你要一行,一列的吃,要你输出可以吃多少块

思路:

这里你如果找没坏的太麻烦了,所以就找坏了的,如果一行(列)都没有坏的,就把标记vis数组对应的位置++,到最后遍历一遍标记数组vis ,可以吃的就算上,输出sum 就好了

#include<iostream>
using namespace std;	
int vis[15][15];
int main(){
	char pre[15][15];
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>pre[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		bool falg=true;
		for(int j=1;j<=m;j++){
			if(pre[i][j]=='S'){
				falg=false;
				break;
			}
		}
		if(falg){
			for(int j=1;j<=m;j++){
				vis[i][j]++;
			}
		}
	}
	for(int i=1;i<=m;i++){
		bool falg=true;
		for(int j=1;j<=n;j++){
			if(pre[j][i]=='S')
			    falg=false;
		}
		if(falg){
			for(int j=1;j<=n;j++){
				vis[j][i]++;
			}
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(vis[i][j]>0)
			    sum++;
		}
	}
	cout<<sum<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/red_red_red/article/details/86683544