如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕。
//cf 192 div2 #include <stdio.h> #include <string.h> int vis[11][11]; char map[11][11]; int main() { int r, c; while (scanf("%d %d", &r, &c) != EOF) { for (int i = 1; i <= r; i++) scanf("%s", &map[i][1]); memset(vis, 0, sizeof (vis)); for (int i = 1; i <= r; i++) { int flag = 1; for (int j = 1; j <= c; j++) { if (map[i][j] == 'S') { flag = 0; break; } } if (flag) { for (int j = 1; j <= c; j++) vis[i][j] = 1; } } for (int i = 1; i <= c; i++) { int flag = 1; for (int j = 1; j <= r; j++) { if (map[j][i] == 'S') { flag = 0; break; } } if (flag) { for (int j = 1; j <= r; j++) vis[j][i] = 1; } } int sum = 0; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { if (vis[i][j] == 1) sum++; } } printf("%d\n", sum); } return 0; }1.