标签:ons for memset col bsp const 表示 can ==
我们可以用四分树来表示一个黑白图像,以根结点表示整幅图像,然后将行列各两等分,从左到右以4各子节点表示。F表示黑色,E表示白色。
代码如下:
1 #include<cstdio> 2 #include<cstring> 3 4 const int len = 32; 5 const int maxn = 1024 + 10; 6 char s[maxn]; 7 int buf[len][len], cnt; 8 9 void draw(const char* s, int& p, int r, int c, int w) { 10 char ch = s[p++]; 11 if (ch == ‘p‘) { 12 draw(s, p, r, c + w / 2, w / 2); 13 draw(s, p, r, c, w / 2); 14 draw(s, p, r + w / 2, c, w / 2); 15 draw(s, p, r + w / 2, c + w / 2, w / 2); 16 } 17 else if (ch == ‘f‘) { 18 for (int i = r; i < r + w; i++) 19 for (int j = c; j < c + w; j++) 20 if (buf[i][j] == 0) { 21 buf[i][j] = 1; cnt++; 22 } 23 } 24 } 25 26 int main() { 27 int T; 28 scanf_s("%d", &T); 29 while (T--) { 30 memset(buf, 0, sizeof(buf)); 31 cnt = 0; 32 for (int i = 0; i < 2; i++) { 33 scanf_s("%s", s); 34 int p = 0; 35 draw(s, p, 0, 0, len); 36 } 37 printf("There are %d black pixels .\n", cnt); 38 } 39 return 0; 40 }
标签:ons for memset col bsp const 表示 can ==
原文地址:http://www.cnblogs.com/PabloZeal/p/7606251.html