Codeforces Round #192 (Div. 2) A. Cakeminator【二维字符数组/吃掉cake,并且是一行或者一列下去,但是该行/列必须没有草莓的存在】
1 second
256 megabytes
standard input
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.
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 the maximum number of cake cells that the cakeminator can eat.
- 3 4
- S...
- ....
- ..S.
- 8
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,并且是一行或者一列下去,但是该行/列必须没有草莓的存在】的更多相关文章
- Codeforces Round #619 (Div. 2)E思维+二维RMQ
题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...
- Codeforces Round #192 (Div. 2) A. Cakeminator
#include <iostream> #include <vector> using namespace std; int main(){ int r,c; cin > ...
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...
- 二维字符数组利用gets()函数输入
举例: ][]; ;i<;i++) gets(a[i]); a是二维字符数组的数组名,相当于一维数组的指针, 所以a[i]就相当于指向第i个数组的指针,类型就相当于char *,相当于字符串.
- 【C/C++】二维数组的传参的方法/二维字符数组的声明,使用,输入,传参
[问题] 定义了一个子函数,传参的内容是一个二维数组 编译提示错误 因为多维数组作为形参传入时,必须声明除第一位维外的确定值,否则系统无法编译(算不出偏移地址) [二维数组的传参] 方法一:形参为二维 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
[链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...
- 二维字符数组利用gets输入
char a[10][81];for(int i=0;i<10;i++)gets(a[i]); a是二维数组的数组名,相当于一维数组的指针,所以a[i]就相当于指向第i个数组的指针,类型就相当于 ...
- J - Borg Maze +getchar 的使用注意(二维字符数组的输入)
题目链接: https://vjudge.net/contest/66965#problem/J 具体思路: 首先将每个点之间的最短距离求出(bfs),A 或者 S作为起点跑bfs,这样最短距离就求出 ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
随机推荐
- neo4j的搭建和实例使用
一. 简介 neo4j是当今最流行的图数据库,基于 节点+关系 的架构,保存了图形数据的基本元素.同时,数据库也支持通过基础数据元素和独特的CQL查询语法,快速方便的检索.构建复杂的图表关系结果. 二 ...
- vue 监听返回
mounted: function() { //使用keep-alive时可以放在activated内 if (window.history && window.history.pus ...
- Install- Linux必学的60个命令
1.作用 install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户. 2.格式 (1)install [选项]... 来源 目的地 (2)install [选项]... 来源... ...
- 关于HTTP协议(转)
HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...
- 简单易学的机器学习算法—SVD奇异值分解
简单易学的机器学习算法-SVD奇异值分解 一.SVD奇异值分解的定义 假设M是一个的矩阵,如果存在一个分解: 其中的酉矩阵,的半正定对角矩阵,的共轭转置矩阵,且为的酉矩阵.这样的分解称为M的奇 ...
- Android App的设计架构:MVC,MVP,MVVM与架构AAAAA
1. 架构设计的目的1.1 通过设计使程序模块化,做到模块内部的高聚合和模块之间的低耦合.1.2 这样做的好处是使得程序在开发的过程中,开发人员只需要专注于一点,提高程序开发的效率,并且更容易进行后续 ...
- Linux 系统的运行级别(runlevel)
Linux 系统有 7 个运行级别,Linux 系统任何时候都运行在一个指定的运行级别上,不同的运行级别所运行的程序和服务不尽相同,所要完成的工作和要达到的目的也不相同 · 运行级别 0 系统停机(h ...
- LINUX超级用户(权限)在系统管理中的作用
1.对任何文件.目录或进程进行操作: 但值得注意的是这种操作是在系统最高许可范围内的操作:有些操作就是具有超级权限的root也无法完成: 比如/proc 目录,/proc 是用来反应系统运行的实时状态 ...
- MAC中已有的虚拟环境在pycharm 中进行调用
首先确定虚拟环境的路径: 打开工作环境配置文件,找到工作目录: 在pycharm中解释器中找到工作目录中对应的虚拟环境进行配置就可以了
- Hackerrank--String Function Calculation(后缀数组)
题目链接 Jane loves string more than anything. She made a function related to the string some days ago a ...