您的位置:首页 > 其它

UVA 297 - Quadtrees

2017-07-21 19:09 274 查看
简单的递归思想,按照紫书的思路,“模拟”绘制相应的矩形区域即可

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
using namespace std;

int T;
int amount;
string s;
int area[32][32];

void Draw(int length,int &pos,int leftx,int lefty,int width){
if (pos >= length) return;
char ch = s[pos];
pos++;
if (ch == 'p'){
Draw(length,pos,leftx,lefty+width/2,width/2);
Draw(length,pos,leftx,lefty,width/2);
Draw(length,pos,leftx+width/2,lefty,width/2);
Draw(length,pos,leftx+width/2,lefty+width/2,width/2);
}
else if (ch == 'f'){
for (int i = leftx; i < leftx + width; i++){
for (int j = lefty; j < lefty + width; j++){
if (area[i][j] == 0){
area[i][j] = 1;
amount++;
}
}
}
}
}

int main(){
cin >> T;
while (T--){
amount = 0;
memset(area,0,sizeof(area));
for (int i = 0; i < 2; i++){
cin >> s;
int length = s.size();
int pos = 0;
int width = 32;
Draw(length, pos, 0, 0, width);
}
cout << "There are " << amount<<" black pixels." << endl;
}
//system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: