A. Cakeminator
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 × 4cake 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 c characters — 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
Note

For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).

【题意】:有一个蛋糕妖怪,只能吃一行或一列上的所有蛋糕,如果某行/列有草莓,就不吃到草莓,问怪兽最多能吃多少蛋糕。

【分析】:设置行,列标记数组判断标记草莓所在行列,vis数组标记这个点吃过与否。

【代码】:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 20;
int cnt;
int n,m,f;
char a[maxn][maxn];
int r[maxn],c[maxn],vis[maxn][maxn];//行标记,列标记,单位元标记
int main()
{
cin>>n>>m;
memset(r,0,sizeof(r));
memset(c,0,sizeof(c));
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
scanf("%s",a[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='S')
{
r[i]=1;
c[j]=1;
}
}
}
for(int i=0;i<n;i++)
{
if(r[i]) continue;
for(int j=0;j<m;j++)
if(!vis[i][j])
{
cnt++;
vis[i][j]=1;
}
}
for(int j=0;j<m;j++)
{
if(c[j]) continue;
for(int i=0;i<n;i++)
{
if(!vis[i][j])
{
cnt++;
vis[i][j]=1;
}
}
}
cout<<cnt<<endl;
return 0;
}

  

Codeforces Round #192 (Div. 2) A. Cakeminator【二维字符数组/吃掉cake,并且是一行或者一列下去,但是该行/列必须没有草莓的存在】的更多相关文章

  1. Codeforces Round #619 (Div. 2)E思维+二维RMQ

    题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...

  2. Codeforces Round #192 (Div. 2) A. Cakeminator

    #include <iostream> #include <vector> using namespace std; int main(){ int r,c; cin > ...

  3. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

  4. 二维字符数组利用gets()函数输入

    举例: ][]; ;i<;i++) gets(a[i]); a是二维字符数组的数组名,相当于一维数组的指针, 所以a[i]就相当于指向第i个数组的指针,类型就相当于char *,相当于字符串.

  5. 【C/C++】二维数组的传参的方法/二维字符数组的声明,使用,输入,传参

    [问题] 定义了一个子函数,传参的内容是一个二维数组 编译提示错误 因为多维数组作为形参传入时,必须声明除第一位维外的确定值,否则系统无法编译(算不出偏移地址) [二维数组的传参] 方法一:形参为二维 ...

  6. 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)

    [链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...

  7. 二维字符数组利用gets输入

    char a[10][81];for(int i=0;i<10;i++)gets(a[i]); a是二维数组的数组名,相当于一维数组的指针,所以a[i]就相当于指向第i个数组的指针,类型就相当于 ...

  8. J - Borg Maze +getchar 的使用注意(二维字符数组的输入)

    题目链接: https://vjudge.net/contest/66965#problem/J 具体思路: 首先将每个点之间的最短距离求出(bfs),A 或者 S作为起点跑bfs,这样最短距离就求出 ...

  9. Codeforces Round #192 (Div. 2) (330A) A. Cakeminator

    题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...

随机推荐

  1. logcat日志文件

    android日志系统提供了记录和查看系统调试信息的功能,日志都是从各个软件和一些系统的缓冲区中记录下来的,缓冲区可以通过logcat命令来进行查看和使用 开发者选项,有个选项叫做“日志记录器缓冲区大 ...

  2. JSON对象获取指定元素以及JSON.parse() 与 JSON.stringify() 的区别

    利用 JSON.parse(param) 实现 例: var param = { "name" : "张三", "text" : { &qu ...

  3. 将ERF格式转换成PCAP格式

    在研究网络流量分析的时候,wireshark默认采用pcap格式.对于用Endace DAG捕捉卡捕获的数据包,一般来说,都是erf格式的.一般来说,此种格式包含了更多了链路层信息.而我们采用wire ...

  4. Bash 常用快捷方式

    从历史中执行命令 ctrl +r 搜索历史命令记录 !$ 重复上一个命令参数 文本编辑的快捷方式 c    分别更改这些配对标点符号中的文本内容 di   分别删除这些配对标点符号中的文本内容 do ...

  5. iftop实时监控网络流量

    需要安装,linux自身不自带该命令 中间的<= =>这两个左右箭头,表示的是流量的方向. TX:发送流量 RX:接收流量 TOTAL:总流量 Cumm:运行iftop到目前时间的总流量 ...

  6. LA4794 Sharing Chocolate

    传送门 记忆化搜索. 在下觉得sxy大佬的代码写得相当好,通篇的骚操作(因为我都不会呀),%%% 学到了 预处理每个状态的值.以前的我都是zz地枚举每一位.. for(int i=1;i<(1& ...

  7. touch滑动事件---简单小案例

    html: <!--导航栏头部--><div class="type_nav"> <ul class="clearfix " v- ...

  8. 用Python输出一个杨辉三角的例子

    用Python输出一个杨辉三角的例子 这篇文章主要介绍了用Python和erlang输出一个杨辉三角的例子,同时还提供了一个erlang版杨辉三角,需要的朋友可以参考下 关于杨辉三角是什么东西,右转维 ...

  9. 匿名/局部内部类访问局部变量时,为什么局部变量必须加final

    我们都知道方法中的匿名/局部内部类是能够访问同一个方法中的局部变量的,但是为什么局部变量要加上一个final呢? 首先我们来研究一下变量生命周期的问题,局部变量的生命周期是当该方法被调用时在栈中被创建 ...

  10. 一维、二维数组 与 常用的返回数组 以及 fetch_all与fetch_row的区别

    一维数组:单行单列的数组. 二维数组:多行多列的数组.       (至少两行两列) 索引数组: fetch_all() 返回所有数组 fetch_row() 返回一行或一列数组  (第二行需要输入两 ...