标签:实现 1.0 names lock 矩阵 pos tree dtree sizeof
1.依旧是一波DFS建树 //矩阵实现
2.建树过程用1.0来填充表示像素
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 const int maxn = 1024 + 5; 6 const int len = 32 ; 7 int tree[len][len],pcount; 8 char str[maxn]; 9 10 void buildtree(char* str,int& pos,int r,int c,int w)//用矩阵来实现四分树 11 { 12 char ch = str[pos++] ; 13 if(ch == ‘p‘) 14 { 15 buildtree(str, pos, r, c+w/2, w/2); // 这个树的第一个结点 16 buildtree(str, pos, r, c , w/2); // 2 17 buildtree(str, pos, r+w/2, c , w/2); // 3 18 buildtree(str, pos, r+w/2, c+w/2, w/2); // 4 19 } 20 else if(ch == ‘f‘) //填像素并统计 ==0说明没填过 21 { 22 for(int i = r; i < r+w; i++) 23 for(int j = c; j < c+w; j++) 24 if(tree[i][j] == 0) { tree[i][j] = 1; pcount++; } 25 } 26 } 27 28 int main(int argc, char *argv[]) 29 { 30 int t ; 31 cin >> t; 32 while(t--) 33 { 34 memset(tree,0,sizeof(tree)) ; 35 pcount = 0 ; 36 for(int i = 0;i < 2; i++) 37 { 38 cin >> str ; 39 int pos = 0; 40 buildtree(str,pos,0,0,len) ; 41 } 42 cout << "There are "<< pcount <<" black pixels." << endl ; 43 } 44 return 0; 45 }
标签:实现 1.0 names lock 矩阵 pos tree dtree sizeof
原文地址:https://www.cnblogs.com/secoding/p/9535783.html