本题思路:
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; }
codeforces A. Cakeminator 题解,码迷,mamicode.com
时间: 2024-10-11 13:41:09