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 & ...
随机推荐
- elasticsearch 中文API 索引(三)
索引API 索引API允许开发者索引类型化的JSON文档到一个特定的索引,使其可以被搜索. 生成JSON文档 有几种不同的方式生成JSON文档 利用byte[]或者作为一个String手动生成 利用一 ...
- [TJOI2017]城市 【树的直径+暴力+优化】
Online Judge:Luogu P3761 Label:树的直径,暴力 题目描述 从加里敦大学城市规划专业毕业的小明来到了一个地区城市规划局工作.这个地区一共有n座城市,n-1条高速公路,保证了 ...
- noi.openjudge 二分法求函数的零点
二分法求函数的零点 总时间限制: 1000ms 内存限制: 65536kB 描述 有函数:f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121 已 ...
- 【python之路45】tornado的用法 (三)
参考:https://www.cnblogs.com/sunshuhai/articles/6253815.html 一.cookie用法补充 1.cookie的应用场景 浏览器端保存的键值对,每次访 ...
- AdaBoost笔记之代码
最近要做二分类问题,先Mark一下知识点和代码,参考:Opencv2.4.9源码分析——Boosting 以下内容全部转自此文 一 原理 二 opencv源码 1.先看构建Boosting的参数: ...
- Java文件写入
一,FileWritter写入文件 FileWritter, 字符流写入字符到文件.默认情况下,它会使用新的内容取代所有现有的内容,然而,当指定一个true (布尔)值作为FileWritter构造函 ...
- [Day2] Nginx静态文件
上一节我们介绍了nginx的三个使用场景和一些配置语法参数,今天我们就用一章的内容来介绍一下Nginx作为静态资源服务器的配置和常见问题. 一. 简单的静态服务器 话不多说,直接上配置代码. se ...
- Python - 基本数据类型及其常用的方法之字典和布尔值
字典 特点:{"key1": value1, "key2":value2} , 键值对中的值可以为任何数据类型,键不能为列表.字典(无法哈希),布尔值可以为键 ...
- 设置div背景图片填满div
可以设置div的样式为 background:url('+UPLOAD_PATH+data.url+') no-repeat; background-size: 100%;width:100%;hei ...
- VS2013 IIS Express8.0
1.下载最新版本的 Microsoft Web Platform Installer 5.0. 2.在组件列表中选择最新版本的 WebMatrix 3.0,安装重启后即可正常使用 IIS Expres ...