202212-3 JPEG 解码(搞错了)

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define LL long long
#define INF 0x3f3f3f3f
#define EPS 1e-12
#define PI 3.141592653579798
#define maxn 1e5+10;
#define MOD 1e9+7;
//#define scanf scanf_s
using namespace std;
inline int rd() {
    int f = 0; int x = 0; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    if (f) x = -x;
    return x;
}

double liang[10][10], m[10][10];
double ef[9] = { 0,sqrt(1.0 / 2.0),1,1,1,1,1,1,1 };
struct zb {
    int x, y;
};
zb judge(zb a) {
    zb b;
    if (a.x + a.y < 9) {
        if ((a.x + a.y) % 2 == 0) {//上
            b.x = a.x - 1;
            if (b.x == 0) b.x++;
            b.y = a.y + 1;
        }
        else {//下
            b.x = a.x + 1;
            b.y = a.y - 1;
            if (b.y == 0) b.y++;
        }
    }
    else {
        if ((a.x + a.y) % 2 == 0) {//上
            if (a.y == 8) b.x = a.x + 1;
            else {
                b.x = a.x - 1;
                b.y = a.y + 1;
            }
        }
        else {//下
            if (a.x == 8) b.y = a.y + 1;
            else {
                b.x = a.x - 1;
                b.y = a.y + 1;
            }
        }
    }
    return b;
}
int main()
{
    for (int i = 1; i <= 8; i++)
        for (int j = 1; j <= 8; j++)
            liang[i][j] = rd();
    int n, t;
    cin >> n >> t;
    zb pos;
    pos.x = 1, pos.y = 1;
    for (int i = 1; i <= n; i++) {
        m[pos.x][pos.y] = rd();
        pos = judge(pos);
    }
    if (t == 0) {
        for (int i = 1; i <= 8; i++) {
            for (int j = 1; j <= 8; j++) {
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
    else if (t == 1) {
        for (int i = 1; i <= 8; i++) {
            for (int j = 1; j <= 8; j++) {
                cout << m[i][j]*liang[i][j] << ' ';
            }
            cout << endl;
        }
    }
    else {
        for (int i = 1; i <= 8; i++) {
            for (int j = 1; j <= 8; j++) {
                double ans = 0, res = 0;
                for (int u = 1; u <= 8; u++) {
                    for (int v = 1; v <= 8; v++) {
                        ans += ef[u] * ef[v] * m[u][v] * liang[u][v] * cos(PI / 8.0 * ((double)(i - 1.0) + 0.5) * (u - 1.0)) * cos(PI / 8.0 * ((double)(j - 1.0) + 0.5) * (v - 1.0));
                    }
                }
                ans = ans / 4.0;
                res = round(ans + 128.0);
                if (res > 255) res = 255;
                if (res < 0) res = 0;
                cout << res << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值