#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 110,M=2*N,mod=1e9+7;
int n,m;
int q[N][N],a[N];
int g[N][N];
double ans[N][N];
double get_a(int x) {
if(x==0) return sqrt(0.5);
return 1;
}
double get_cos(int x,int y) {
return cos((x+0.5)*y*acos(-1)/8);
}
double get_num(int x,int y) {
double res=0;
for(int i=0;i<8;i++) {
for(int j=0;j<8;j++) {
res+=get_a(i)*get_a(j)*q[i][j]*get_cos(x,i)*get_cos(y,j);
}
}
return res;
}
void solve() {
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
cin >> q[i][j];
int op;
cin >> n >> op;
for(int i=1;i<=n;i++) {
cin >> a[i];
}
int cnt=1,x=0,y=0;
while(cnt<=n) { //将给定的数组的值对应到二维矩阵中,应该还可以简化写法
g[x][y]=a[cnt++];
if((x+y)%2==0) {
if((x+y)<=7) {
if(x==0) y++;
else x--,y++;
}
else if((x+y)>7) {
if(y==7) x++;
else x--,y++;
}
} else if((x+y)%2!=0) {
if((x+y<7)) {
if(y==0) x++;
else x++,y--;
}
else if((x+y)>=7) {
if(x==7) y++;
else x++,y--;
}
}
}
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
q[i][j]*=g[i][j];
if(op==0) {
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
cout << g[i][j] << " ";
cout << endl;
}
} else if(op==1) {
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
cout << q[i][j] << " ";
cout << endl;
}
} else if(op==2) {
for(int i=0;i<8;i++) {
for(int j=0;j<8;j++) {
ans[i][j]=0.25*get_num(i,j);
int tmp=(int)(ans[i][j]+128+0.5);
if(tmp>255) tmp=255;
else if(tmp<0) tmp=0;
printf("%d ",tmp);
}
printf("\n");
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
//cin >> t;
t=1;
while(t--) {
solve();
}
return 0;
}
/*
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
26
2
-26 -3 0 -3 -2 -6 2 -4 1 -3 1 1 5 1 2 -1 1 -1 2 0 0 0 0 0 -1 -1
*/
感觉第三题比之前的简单多啦,模拟题,而且数据范围也很小。