测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A22932. 星球

填空题 困难

题目描述

星球

题目描述

星域是 2ⁿ×2ⁿ个星球组成的正方形,安全星球识别规则:

   1. 均分为 4 个更小正方形区域;

   2. 左上角区域星球安全(用 "." 表示);

   3. 其余三个区域递归划分至单个星球;

   4. 未标记安全的星球危险(用 "*" 表示)。输出安全地图。

输入格式

输入一个整数 n。

输出格式

输出每个星球的安全性。

输入样例

3

输出样例

.......*
......**
.....*.*
....****
...*...*
..**..**
.*.*.*.*
********

参考答案

#include<iostream> const int max_size = 5050; bool c[max_size][max_size] = {false}; void draw(int size, int x, int y) { if (size == 1) { c[x][y] = true; } else { int half = size / 2; draw(half, x + half, y); draw(half, x, y + half); draw(half, x + half, y + half); } } void print(int n) { int length = 1 << n; draw(length, 0, 0); for (int x = 0; x < length; ++x) { for (int y = 0; y < length; ++y) { if (c[x][y]) std::cout << '*'; else std::cout << '.'; } std::cout << "\n"; } } int main(){ int n; std::cin >> n; print(n); }
上一题 下一题