Problem-330A-Codeforce Cakeminator(思维)

àì夳堔傛蜴生んèń 2022-06-07 00:45 220阅读 0赞

A. Cakeminator

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 as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4cake may look as follows:

69d63321d7275bb341b061fd3e6cc4a417f89c88.png

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.

Input

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 rlines 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

Output the maximum number of cake cells that the cakeminator can eat.

Examples

input

  1. 3 4
  2. S...
  3. ....
  4. ..S.

output

  1. 8

Note

For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).

2506be8fee1e31feaf37d340e42e9c9a2fa5f7b3.png3ea69c95528a6d3311ccc7b187f29d57bb703bb0.pnge0e9a84805874121c6cede2df70efd8b66905352.png思路:最后剩下的那一块,一定是行、列都有草莓出现。所以能吃掉的数量就等于总数-(所有草莓的数量 + 任意两个草莓交叉点的数量(注意不要重复));

  1. #include<stdio.h>
  2. #include<cstring>
  3. using namespace std;
  4. const int maxn=11;
  5. //const int INF=0x3f3f3f3f;
  6. int n, m;
  7. char mp[maxn][maxn];
  8. int cnt=0, tx[maxn*maxn], ty[maxn*maxn], st[maxn][maxn];
  9. int main()
  10. {
  11. scanf("%d%d", &n, &m);getchar();
  12. for(int i=1; i<=n; i++)
  13. {
  14. for(int j=1; j<=m; j++)
  15. {
  16. mp[i][j]=getchar();
  17. if(mp[i][j]=='S')
  18. {
  19. cnt++;
  20. st[i][j]=1;
  21. tx[cnt]=i;
  22. ty[cnt]=j;
  23. }
  24. }
  25. getchar();
  26. }
  27. int sum=cnt;
  28. for(int i=1; i<=sum; i++)
  29. {
  30. for(int j=1; j<=sum; j++)
  31. {
  32. if(!st[tx[i]][ty[j]])
  33. {
  34. st[tx[i]][ty[j]]=1;
  35. cnt++;
  36. }
  37. }
  38. }
  39. printf("%d\n", n*m-cnt);
  40. return 0;
  41. }

发表评论

表情:
评论列表 (有 0 条评论,220人围观)

还没有评论,来说两句吧...

相关阅读