1 /* 2 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 3 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最小的,脑洞大 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 const int MAXN = 55; 12 const int INF = 0x3f3f3f3f; 13 char s[MAXN][MAXN]; 14 bool vis[MAXN][MAXN]; 15 int n, m; 16 17 int main(void) { //HDOJ 5319 Painter 18 //freopen ("1004.in", "r", stdin); 19 20 int T; scanf ("%d", &T); 21 while (T--) { 22 scanf ("%d", &n); 23 for (int i=1; i<=n; ++i) scanf ("%s", s[i] + 1); 24 memset (vis, false, sizeof (vis)); m = strlen (s[1] + 1); 25 26 int ans = 0; 27 for (int i=1; i<=n; ++i) { 28 for (int j=1; j<=m; ++j) { 29 if (s[i][j] == ‘R‘ || s[i][j] == ‘G‘) { 30 if (!(s[i-1][j-1] == ‘R‘ || s[i-1][j-1] == ‘G‘)) ans++; 31 } 32 } 33 } 34 for (int i=1; i<=n; ++i) { 35 for (int j=1; j<=m; ++j) { 36 if (s[i][j] == ‘B‘ || s[i][j] == ‘G‘) { 37 if (!(s[i-1][j+1] == ‘B‘ || s[i-1][j+1] == ‘G‘)) ans++; 38 } 39 } 40 } 41 printf ("%d\n", ans); 42 } 43 44 return 0; 45 }
时间: 2024-12-09 07:55:17