zoukankan      html  css  js  c++  java
  • 137

    Poker Face

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    As is known to all, coders are lack of exercise and Kato is one of them. In order to get fit, he decides to go mining in MINECRAFT. However, it is always dangerous in the mine because there are a lot of ZOMBIEs in MINECRAFT. They kill Kato time and time again when he is mining. But this time, Kato is in invincible mode and wants to observe what the ZOMBIEs' faces are like. After his obervation, he found that the ZOMBIEs' faces are regular. Now he provides you the ZOMBIEs' faces of size 8, 16 and 32, it is your task to draw the other ZOMBIEs. You should find the recursivepattern from the small cases and learn to draw bigger cases.

    Input

    There are multiple test cases. For each case there is only a number N (8 ≤ N≤ 1024, N is a power of 2), which is size of the ZOMBIE's face. The input ends with an integer less than eight.

    Output

    For each case, output the image of the ZOMBIE's face. And print an empty line after each case.

    Sample Input

    8
    16
    32
    0
    

    Sample Output

    ********
    ***  ***
    ***  ***
    ***  ***
    * **** *
    * *  * *
    * *  * *
    ********
    
    ****************
    *              *
    * ****    **** *
    * *  *    *  * *
    * *  *    *  * *
    * *  *    *  * *
    * ****    **** *
    *              *
    *   ********   *
    *   * *  * *   *
    *   * *  * *   *
    *   * **** *   *
    *   ***  ***   *
    *   ***  ***   *
    *   ***  ***   *
    ****************
    
    ********************************
    *                              *
    *                              *
    *                              *
    *   ********        ********   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   *      *        *      *   *
    *   ********        ********   *
    *                              *
    *                              *
    *                              *
    *       ****************       *
    *       *   ***  ***   *       *
    *       *   ***  ***   *       *
    *       *   ***  ***   *       *
    *       *   * **** *   *       *
    *       *   * *  * *   *       *
    *       *   * *  * *   *       *
    *       *   ********   *       *
    *       *              *       *
    *       * ****    **** *       *
    *       * *  *    *  * *       *
    *       * *  *    *  * *       *
    *       * *  *    *  * *       *
    *       * ****    **** *       *
    *       *              *       *
    ********************************
    
    

    Hint

    The sample out put is the ZOMBIE's face of size 8, 16, 32.

    Author: ZHU, Heming

    解题:递推打印就是了。。。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <vector>
    #include <queue>
    #include <cstdlib>
    #include <string>
    #include <set>
    #include <stack>
    #define LL long long
    #define INF 0x3f3f3f3f
    #define pii pair<int,int>
    using namespace std;
    const int maxn = 2000;
    int n;
    char table[11][maxn][maxn];
    void printLine(int m,int n,int x,int y) {
        for(int i = 0; i < n; ++i)
            table[m][x][y+i] = '*';
    }
    void printR(int m,int n,int x,int y) {
        for(int i = 0; i < n-1; ++i) {
            table[m][x+i][y] = '*';
            for(int j = 1; j < n-1; ++j)
                table[m][x+i][y+j] = ' ';
            table[m][x+i][y+n-1] = '*';
        }
    }
    void printG(int m,int n) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j)
                putchar(table[m][i][j]);
            putchar('
    ');
        }
    }
    void printB(int n,int x,int y,int m) {
        for(int i = n-1; i >= 0; --i) {
            for(int j = 0; j < n; ++j) {
                table[m][x+i][y+j] = table[m-1][i][j];
            }
        }
    }
    void draw(int m,int n) {
        printLine(m,n,0,0);
        printR(m,n,1,0);
        printLine(m,n,n-1,0);
    
        printLine(m,n>>2,n>>3,n>>3);
        printR(m,n>>2,(n>>3)+1,n>>3);
        printLine(m,n>>2,(n>>3)+(n>>2),n>>3);
    
        printLine(m,n>>2,n>>3,n-(n>>3)-(n>>2));
        printR(m,n>>2,(n>>3)+1,n-(n>>3)-(n>>2));
        printLine(m,n>>2,(n>>3)+(n>>2),n-(n>>3)-(n>>2));
    }
    void draw2(int m,int n) {
        int y = n>>2;
        int x = (n>>1);
        for(int i = (n>>1)-1; i >= 0; --i,x++) {
            for(int j = 0; j < (n>>1); ++j)
                table[m][x][y+j] = table[m-1][i][j];
        }
    }
    int main() {
        memset(table,' ',sizeof(table));
        draw(3,1<<3);
        printLine(3,4,4,2);
        table[3][5][2] = table[3][5][5] = '*';
        table[3][6][2] = table[3][6][5] = '*';
        for(int i = 4; i <= 10; ++i) {
            draw(i,1<<i);
            draw2(i,1<<i);
        }
        while(scanf("%d",&n),n >= 8) {
            int k = log2(n)+0.5;
            printG(k,n);
            putchar('
    ');
        }
        return 0;
    }
    View Code
  • 相关阅读:
    409. Longest Palindrome(计算一组字符集合可以组成的回文字符串的最大长度)
    242. Valid Anagram(两个字符串包含的字符是否完全相同)
    17. Letter Combinations of a Phone Number(电话号码的字母组合)
    模块XML真垃圾
    数据库是什么
    python项目开发规范
    面向对象之类的成员
    面向对象
    模块之 import os 模块一
    模块之序列化 import json
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4133174.html
Copyright © 2011-2022 走看看