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;
}
#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;
}
相关文章推荐
- 6-11 四分树(Quadtrees, UVa 297)
- UVA 297 Quadtrees(四叉树建树、合并与遍历)
- UVA.297 Quadtrees (四分树 DFS)
- Uva297——Quadtrees
- UVA 297 - Quadtrees(建树)
- UVa 297 (四分树 递归) Quadtrees
- UVa 297 Quadtrees -SilverN
- UVA 297 Quadtrees(四叉树建树、合并与遍历)
- UVA 297 Quadtrees(四叉树)
- UVa 297 Quadtrees(模拟&四分树)
- uva 297 Quadtrees
- UVA 297 Quadtrees(四叉树建树、合并与遍历)
- uva 297 quadtrees——yhx
- UVA 297 Quadtrees
- uva-297 Quadtrees
- Uva - 297 - Quadtrees
- UVA297 Quadtrees(递归!!!)
- Quadtrees UVA - 297
- Uva297 Quadtrees【递归建四分树】【例题6-11】
- UVA 297 Quadtrees 好像不是很难。又好像不是很简单