首页 > 代码库 > codeforces A. Cakeminator 题解
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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。