zoukankan      html  css  js  c++  java
  • 四分树 (Quadtrees UVA

    题目描述:

    原题:https://vjudge.net/problem/UVA-297

    题目思路:

    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 }
  • 相关阅读:
    努力
    散步
    相信自己
    我仅有的倔强
    存储过程 有用
    面试题整理 !=!=未看 *****面试题整理最全 有用
    项目介绍4 y有用
    面试题;40个多线程的问题 背1 有用
    面试题: redis面试题 有用 redis详细
    数据库相关内容 已看1 有用
  • 原文地址:https://www.cnblogs.com/secoding/p/9535783.html
Copyright © 2011-2022 走看看