题目
近几次第三题有变的越来越简单的趋势啊
代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+100;
int n , T;
int a[65]={0};
int b[8][8] , c[8][8] ,d[8][8] , e[8][8];
int result[8][8];
//0,0 --> 0,1
//0,1 --> 1,0
//1,0 --> 2,0
//2,0 --> 0,2
//
//0,2 --> 0,3
//0,3 --> 1,2 --> 2,1 --> 3,0
//3,0 --> 4,0
//4,0 --> 0,4
void advert_value(int arr1[8][8], int arr2[8][8])
{
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
arr1[i][j] = arr2[i][j];
}
}
int main()
{
for(int i=0;i<=7;i++)
for(int j=0;j<=7;j++)
cin>>b[i][j];
cin>>n>>T;
for(int i=0;i<n;i++) cin>>a[i];
// 初始化,从(0,0)开始
int k=0,x=0,y=0;
// 赋值
c[x][y]=a[k++];
while(1)
{
// 第一步
y+=1; c[x][y]=a[k++];
// 第二步
while(y != 0)
{
x+=1; y-=1;
c[x][y]=a[k++];
}
//第三步
if(x == 7) break;
else
{
x+=1;
c[x][y]=a[k++];
}
// 第四步
while(x != 0)
{
x-=1; y+=1;
c[x][y]=a[k++];
}
}
// 初始化,从最后一个倒过来推,和上面刚好相反
int k1=63,x1=7,y1=7;
c[x1][y1]=a[k1--];
while(1)
{
// 第一步
y1-=1; c[x1][y1]=a[k1--];
// 第二步
while(y1!=7)
{
x1-=1; y1+=1;
c[x1][y1]=a[k1--];
}
//第三步
if(x1 == 0) break;
else
{
x1-=1;
c[x1][y1]=a[k1--];
}
// 第四步
while(x1 != 7)
{
x1+=1; y1-=1;
c[x1][y1]=a[k1--];
}
}
//与量化矩阵相乘
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
d[i][j]=b[i][j] * c[i][j];
}
// 离散余弦逆变换
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
double res=0;
for(int u=0;u<=7;u++)
{
for(int v=0;v<=7;v++)
{
double m1 = u == 0 ? pow(0.5,0.5) : 1;
double m2 = v == 0 ? pow(0.5,0.5) : 1;
res += m1 * m2 * d[u][v] * cos(u * (i + 0.5) * acos(-1) / 8) * cos(v * (j + 0.5) * acos(-1) / 8);
}
}
int mid = round(0.25 * res + 128);
if(mid < 0) mid = 0;
if(mid > 255) mid = 255;
e[i][j] = mid;
}
}
// 赋值操作
if(T == 0) advert_value(result , c);
else if(T == 1) advert_value(result , d);
else advert_value(result , e);
for(int i = 0; i <= 7;i++)
{
for(int j = 0; j <= 7; j++)
cout << result[i][j] << " ";
cout << endl;
}
return 0;
}