201909-3 CSP认证 字符画 100分

    这个应该是众多第三题中最简单的了,题目有点难读,不过也是CSP的风格,讲的是有一个 屏幕,给你每个像素的三原色的色度,把屏幕分好多块,然后输出每一块的色度,每一块的色度是这块中像素的平均值。

大小关系如下:

     屏幕 (m * n)------- >   分块 (p * q) --------->  像素  ------- > 三原色

模拟的话,先吧每一块的颜色色度处理出来,然后处理一下输出就行。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e6+5;
int s[2005][2005][3];
char ss[10];
int m,n,p,q;
string k1 = "\\x1B\\x5B\\x34\\x38\\x3B\\x32\\x3B";
string k2 = "\\x1B\\x5B\\x30\\x6D";
struct node
{
    int f,s,t;
}C[MAXN];
void fun(int x)
{
    int tp[10];
    int pp = 0;
    if(!x) tp[++pp] = 0;
    while(x)
    {
        tp[++pp] = x%10;
        x/=10;
    }
    for(int i=pp;i>=1;i--){
        printf("\\x3");
        printf("%d",tp[i]);
    }
}
int tot = 0;
int ctoi(char ss)
{
    if(ss>='0' && ss<='9')return ss-'0';
    if(ss>='a' && ss<='f')return ss-'a'+10;
    if(ss>='A' && ss<='F')return ss-'A'+10;
}
int main()
{
  //  while(~scanf("%d%d%d%d",&m,&n,&p,&q)){
        scanf("%d%d%d%d",&m,&n,&p,&q);
        tot = 0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%s",ss);
                int len = strlen(ss),fir,sec,thr;
                if(len == 7){
                    fir = ctoi(ss[1])*16+ctoi(ss[2]);
                    sec = ctoi(ss[3])*16+ctoi(ss[4]);
                    thr = ctoi(ss[5])*16+ctoi(ss[6]);
                }
                if(len == 4){
                    fir = ctoi(ss[1])*16+ctoi(ss[1]);
                    sec = ctoi(ss[2])*16+ctoi(ss[2]);
                    thr = ctoi(ss[3])*16+ctoi(ss[3]);
                }
                if(len == 2){
                    fir = sec = thr = ctoi(ss[1])*16+ctoi(ss[1]);
                }
                s[i][j][0] = fir;
                s[i][j][1] = sec;
                s[i][j][2] = thr;
            }
        }
        int xx = n/q,yy = m/p;
        for(int i=1;i<=xx;i++){
            for(int j=1;j<=yy;j++){
                int f = 0,se = 0,t = 0;
                int st_x = (i-1)*q+1,ed_x = i*q;
                int st_y = (j-1)*p+1,ed_y = j*p;
                for(int k = st_x;k<=ed_x;k++){
                    for(int r = st_y;r<=ed_y;r++){
                        f += s[k][r][0];
                        se += s[k][r][1];
                        t += s[k][r][2];
                    }
                }
                f /= (p*q); se /= (p*q); t /= (p*q);
                C[++tot].f = f;C[tot].s = se;C[tot].t = t;
            }
        }
        int cnt = 0;
        int now_f = 0,now_s = 0,now_t = 0;
        for(int i=1;i<=tot;i++){
            if(C[i].f == now_f && C[i].s == now_s && C[i].t == now_t){
                ///啥也不干
            }
            else if(C[i].f == 0 && C[i].s == 0&&C[i].t == 0){
                ///变默认
                cout<<k2;
            }
            else{
                ///改变颜色
                cout<<k1;
                fun(C[i].f);printf("\\x3B");
                fun(C[i].s);printf("\\x3B");
                fun(C[i].t);printf("\\x6D");
            }
            now_f = C[i].f;now_s = C[i].s;now_t = C[i].t;
            printf("\\x20");
            cnt++;
            if(cnt == m/p){
                cnt = 0;
                if(now_f !=0 || now_s!=0 || now_t != 0)cout<<k2;
                now_f = 0;now_s = 0;now_t = 0;

                printf("\\x0A");
            }
        }
   // }
}
/*
1 1
1 1
#010203

2 2
1 2
#111111
#0
#000000
#111

3 2
1 2
#0
#0
#010101
#010102
#0
#0
\x1B\x5B\x34\x38\x3B\x32\x3B\x30\x3B\x30\x3B\x31\x6D\x20\x1B\x5B\x30\x6D\x20\x20\x0A
*/















      

猜你喜欢

转载自blog.csdn.net/qq_41645482/article/details/104269435