zoukankan      html  css  js  c++  java
  • 字符画

    字符画

    通過樣例猜題意系列

    注意讀題:每輸出完一行需要恢復背景色

    這題用cout瘋狂爆零什麽鬼

    #include <iostream>
    #include <string>
    #include <cstdio>
    using namespace std;
    int A[2004][2003][3];
    int n, m, p, q;
    string color;
    int ati(char c)
    {
        if (c >= 'A' && c <= 'Z')
        {
            return c - 'A' + 10;
        }
        else
            return c - '0';
    }
    
    char* reset = "\x1B\x5B\x30\x6D";
    char* ESC = "\x1B";
    void ito(int x)
    {
        //printf("\x%02X",x);
        //cout << "\x";
        char s[3] ;
        s[2]='';
        int a = x % 16;
        x /= 16;
        int b = x % 16;
        if (a >= 10)
        {
            s[1] = char(a - 10 + 'A');
        }
        else
            s[1] = char(a + '0');
        if (b >= 10)
        {
            s[0] = char(b - 10 + 'A');
        }
        else
            s[0] = char(b + '0');
        printf("\x%s",s);
    }
    void init(int x, int y)
    {
        int len = color.length();
        for (int i = 0; i < len; i++)
        {
            if (color[i] >= 'a' && color[i] <= 'z')
                color[i] = char(color[i] - 'a' + 'A');
        }
        if (len == 7)
        {
            A[x][y][0] = ati(color[1]) * 16 + ati(color[2]);
            A[x][y][1] = ati(color[3]) * 16 + ati(color[4]);
            A[x][y][2] = ati(color[5]) * 16 + ati(color[6]);
        }
        else if (len == 4)
        {
            A[x][y][0] = ati(color[1]) * 16 + ati(color[1]);
            A[x][y][1] = ati(color[2]) * 16 + ati(color[2]);
            A[x][y][2] = ati(color[3]) * 16 + ati(color[3]);
        }
        else
        {
            A[x][y][0] = A[x][y][1] = A[x][y][2] = ati(color[1]) * 16 + ati(color[1]);
        }
    }
    int B[2005][2005][3];
    void del(int x)
    {
        int a = x % 10;
        x /= 10;
        int b = x % 10;
        x /= 10;
        int d = x;
        char c;
        c = (d + '0');
        if (d != 0)
        {
             ito(c);
        }
        c = (b + '0');
        if (b != 0 || d != 0)
        {
             ito(c);
        }
        c = (a + '0');
        ito(c);
    }
    
    int main()
    {
    
        ios::sync_with_stdio(false);
        cin >> m >> n >> p >> q;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cin >> color;
                init(i, j);
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                for (int k = 0; k < 3; k++)
                    B[i / q][j / p][k] += A[i][j][k];
            }
        }
        for (int i = 0; i < n / q; i++)
        {
            for (int j = 0; j < m / p; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    B[i][j][k] /= (p * q);
                }
            }
        }
    
        int be[] = {0,0,0};
        for (int i = 0; i < n / q; i++)
        {
            be[0] = be[1] = be[2] = 0;
            for (int j = 0; j < m / p; j++)
            {
                if ((B[i][j][0] != be[0] || B[i][j][1] != be[1] || B[i][j][2] != be[2])&&(B[i][j][0] == 0 && B[i][j][1] == 0 && B[i][j][2] == 0))
                {
                    printf("%s",reset);
                }
                else
                {
                    if (B[i][j][0] != be[0] || B[i][j][1] != be[1] || B[i][j][2] != be[2])
                    {
                        printf("%s",ESC);  ito('[') ; ito('4') ;ito('8') ; ito(';') ; ito('2') ; ito(';');
                        del(B[i][j][0]);
                        ito(';');
                        del(B[i][j][1]);
                         ito(';');
                        del(B[i][j][2]);
                         ito('m');
                    }
                }
                for (int k = 0; k < 3; k++)
                {
                    be[k] = B[i][j][k];
                }
                 ito((' '));
            }
            if (be[0] != 0 || be[1] != 0 || be[2] != 0)
            {
                 printf("%s",reset);
            }
            ito(('
    '));
        }
    }
    /*
    2 2
    2 1
    #111111
    #0
    #000000
    #000
    x1Bx5Bx34x38x3Bx32x3Bx38x3Bx38x3Bx38x6Dx20x1Bx5Bx30x6Dx0Ax20x0A
    x1Bx5Bx34x38x3Bx32x3Bx38x3Bx38x3Bx38x6Dx20x1Bx5Bx30x6Dx0Ax20x0A
    
    
    */
  • 相关阅读:
    POJ-2096-Collecting Bugs(概率DP)
    2019ICPC南京网络赛总结
    LOJ-6285-数列分块入门9
    LOJ-6284-数列分块入门8
    LOJ-6283-数列分块7
    bzoj2049: [Sdoi2008]Cave 洞穴勘测
    bzoj1010: [HNOI2008]玩具装箱toy
    bzoj1597: [Usaco2008 Mar]土地购买
    bzoj1233: [Usaco2009Open]干草堆tower 单调队列优化dp
    bzoj2442&&codevs4654 单调队列优化dp
  • 原文地址:https://www.cnblogs.com/liulex/p/11917663.html
Copyright © 2011-2022 走看看