UVA 297

来源:互联网 发布:电商部门美工 编辑:程序博客网 时间:2024/06/05 16:32

简单的递归思想,按照紫书的思路,“模拟”绘制相应的矩形区域即可

#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;}

原创粉丝点击