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

    题意:求两棵四分树合并之后黑色像素的个数。

    分析:边建树边统计。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    typedef long long ll;
    typedef unsigned long long llu;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
    const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    const double pi = acos(-1.0);
    const double eps = 1e-8;
    const int MAXN = 1100 + 10;
    const int MAXT = 40 + 10;
    using namespace std;
    char s[MAXN];
    int vis[MAXT][MAXT];
    int cnt;
    void dfs(int &id, int r, int c, int len){
        char cc = s[id++];//传参加自增,遍历每个元素
        if(cc == 'p'){
            dfs(id, r, c + len / 2, len / 2);//1
            dfs(id, r, c, len / 2);//2
            dfs(id, r + len / 2, c, len / 2);//3
            dfs(id, r + len / 2, c + len / 2, len / 2);//4
        }
        else if(cc == 'f'){
            for(int i = r; i < r + len; ++i){
                for(int j = c; j < c + len; ++j){
                    if(!vis[i][j]){
                        vis[i][j] = 1;
                        ++cnt;
                    }
                }
            }
        }
    }
    int main(){
        int T;
        scanf("%d", &T);
        while(T--){
            memset(vis, 0, sizeof vis);
            cnt = 0;
            for(int i = 0; i < 2; ++i){
                scanf("%s", s);
                int id = 0;
                dfs(id, 0, 0, 32);
            }
            printf("There are %d black pixels.\n", cnt);
        }
        return 0;
    }
  • 相关阅读:
    Maven下载Jar包(bat脚本)
    在CentOS7环境下安装Mysql
    在CentOS7下安装JDK1.8
    教你如何进行暗网之旅
    在CentOS7下搭建Hadoop2.9.0集群
    查询IP地址的免费API
    HTTP请求代理类(GET 、 POST 、PUT 、DELETE)
    JAVA 实现 GET、POST、PUT、DELETE HTTP请求
    002---rest_framework认证组件
    001---CBV和restful规范
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6265728.html
Copyright © 2011-2022 走看看