UVA - 297 Quadtrees (四分树)

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

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[] = {, , -, };
const int dc[] = {-, , , };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
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 / , len / );//
dfs(id, r, c, len / );//
dfs(id, r + len / , c, len / );//
dfs(id, r + len / , c + len / , len / );//
}
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] = ;
++cnt;
}
}
}
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
memset(vis, , sizeof vis);
cnt = ;
for(int i = ; i < ; ++i){
scanf("%s", s);
int id = ;
dfs(id, , , );
}
printf("There are %d black pixels.\n", cnt);
}
return ;
}
上一篇:【紫书】Quadtrees UVA - 297 四叉树涂色


下一篇:linux 查找文件的命令