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 asRLimit × limitCGrid. Each cell either has an edevil strawberry, or is empty. For example,
A 3 rows x rows 4 cake 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 edevil 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 integersRAndC(2 cores ≤ CoresR, Bytes,CLimit ≤ limit 10 ),
Denoting the number of rows and the number of columns of the cake. The nextRLines each containsCCharacters
-J-Th character ofI-Th
Line denotes the content of the cell at rowIAnd ColumnJ,
And is either one of these:
- '.' Character denotes a cake cell with no edevil strawberry;
- 'S 'character denotes a cake cell with an edevil strawberry.
Output
Output the maximum number of cake cells that the cakeminator can eat.
Sample test (s) Input
3 4S.........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 ).
Explanation: The question means to solve the sum of the number of all the cakes without the strawberry label in this row or column. You can mark the row and column of the strawberry first, then, you can determine whether there are any strawberries in this row or column for a cake. If not, add them.
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main(){int n,m,i,j;int r[11],c[11];int ans=0;char ch;memset(r,0,sizeof(r));memset(c,0,sizeof(c));scanf("%d %d",&n,&m);for(i=0;i<n;++i){for(j=0;j<m;++j){cin>>ch;if(ch=='S'){r[i]=c[j]=1;}}}ans=n*m;for(i=0;i<n;++i){for( j=0;j<m;++j) {if(r[i] && c[j]) {ans--;}}}printf("%d\n",ans);return 0;}