• 方阵形对角矩阵


    DB_Question

     

    解决:

      1、存

      2、验证

     1 #include <iostream>
     2 using namespace std;
     3 
     4 //将小矩阵的值转存在一维数组b中
     5 void TurnToB(int a[][16], int b[], int m, int t);
     6 //关键的存放算法
     7 void CoreStore(int b[], int x, int y, int val, int m);
     8 //验证i,j到k是否正确,具体检验k是否能输出
     9 void show(int b[], int i, int j, int m);
    10 
    11 int main()
    12 {
    13     int n = 16, m = 4, t = 4;//以16×16方阵为例
    14     int a[16][16];
    15     int b[64];//m*m*t
    16     //初始化特殊位置的值
    17     a[0][0] = 0, a[0][3] = 3, a[3][0] = 3;
    18     a[3][3] = 6, a[7][4] = 11, a[4][7] = 11;
    19     a[7][7] = 14, a[8][11] = 19, a[11][8] = 19;
    20     a[11][11] = 22, a[12][15] = 27, a[15][12] = 27;
    21     a[15][15] = 30, a[5][5] = 10, a[10][11] = 21;
    22     //-------------------------------------------
    23     TurnToB(a, b, m, t);
    24     //验证上一步算法的正确性
    25     show(b, 0, 0, m);
    26     show(b, 0, 3, m);
    27     show(b, 3, 0, m);
    28     show(b, 3, 3, m);
    29 
    30     show(b, 7, 4, m);
    31     show(b, 4, 7, m);
    32     show(b, 7, 7, m);
    33     show(b, 8, 11, m);
    34 
    35     show(b, 11, 8, m);
    36     show(b, 11, 11, m);
    37     show(b, 12, 15, m);
    38     show(b, 15, 12, m);
    39 
    40     show(b, 15, 15, m);
    41     show(b, 5, 5, m);
    42     show(b, 10, 11, m);
    43 
    44     return 0;
    45 }
    46 void TurnToB(int a[][16], int b[], int m, int t)
    47 {
    48     int x, y;
    49     for (int i = 0; i < m; i++)
    50     {
    51         for (int j = 0; j < m; j++)
    52         {
    53             for (int k = 0; k < t; k++)
    54             {
    55                 x = i + m*k;
    56                 y = j + m*k;
    57                 CoreStore(b, x, y, a[x][y], m);
    58             }
    59         }
    60     }
    61 }
    62 void CoreStore(int b[], int x, int y, int val, int m)
    63 {
    64     int loc = (x / m)*m*m + (x%m)*m + y - (x / m)*m;
    65     b[loc] = val;
    66 }
    67 void show(int b[], int i, int j, int m)
    68 {
    69     int loc = (i / m)*m*m + (i%m)*m + j - (i / m)*m;
    70     cout << "a[" << i << "][" << j << "]=b[" << loc << "]=" << b[loc] << endl;
    71 }
    View Code
  • 相关阅读:
    vue简单分屏(1,4,9,16),全屏,还需要调整
    vue 中的Vuex实践
    常用工具类
    java Log日志规范
    spring中对象的注入方式
    不恰当的update语句使用主键和索引导致mysql死锁
    JPA规范及其它持久层框架
    webservice基本功能介绍
    Activiti工作流(二)之常用操作
    Activiti工作流(一)之基本操作介绍
  • 原文地址:https://www.cnblogs.com/guoyujiang/p/11807433.html
Copyright © 2020-2023  润新知