## c语言生成zigzag矩阵 原

itfanr

00  01  05  06
02  04  07  12
03  08  11  13
09  10  14  15
#include <stdio.h>

/*
0， 1， 5， 6，
2， 4， 7，12，
3， 8， 11，13，
9, 10， 14， 15.
*/
int vect[4][4] = {0};
void next(int vect[][4], int *i , int *j ,bool flag){
int tmp = vect[*i][*j] +1;
if(flag){
*i = *i + 1 ;	//down
*j = *j - 1 ;
//printf("down i = %d\n", *i);
vect[*i][*j] = tmp  ;
//printf("down vect[%d][%d] = %d\n", *i,*j ,vect[*i][*j]);
}
else{
*i = *i - 1 ;	//up
*j = *j + 1 ;
//printf("up i = %d\n", *i);
vect[*i][*j] = tmp  ;
//printf("up vect[%d][%d] = %d\n", *i, *j ,vect[*i][*j]);
}

};

void print(){
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
//printf("vect[%d][%d] = %d ", i,j ,vect[i][j]);
printf("%02d  ", vect[i][j]);
}
printf("\n");
}
}

int main(int argc, char const *argv[])
{
const int N = 4 ;
int j = 0 , i = 0;

int count = 2;
int total = 2 * N ;
int line = 1 ;
bool down = false  ; //up
bool change = false ;
while(line < total ) {

if(down){
int tmp = vect[i][j] ;
if(change){
j ++ ;
}else{
i ++ ;
}
vect[i][j] = tmp+1 ;
down = false ;

}else{  //up
int tmp = vect[i][j] ;
if(change){
i++ ;
}else{
i = 0 ;
j++;
}
vect[i][j] = tmp+1 ;
down = true ;
}

//printf("count = %d\n", count);// 2
//printf("out of while : vect[%d][%d] = %d\n", i,j ,vect[i][j]);
int curr = 0 ;
while(curr < count -1  ){
//printf("now j =%d , i= %d \n" , j , i) ;
//printf("vect= %d \n" , vect[i][j]) ;
//printf("down flag is %d\n", down );
next(vect , &i , &j, down) ;
curr++ ;
//printf("\n");
}

line ++ ;
if(change){
count -- ;
}else{
count ++ ;
if(count > N ) {
change = true ;
count = count -2 ;
}
}

}
print() ;
return 0 ;
}

### itfanr

1 DCT变换 经过DCT变换，实现了频率的集中。 2量化 经过量化，我们对DCT变换后的系数进行以QP=28的量化，此时得到了一些左上角集中了非零值的系数矩阵。 3 ZigZag扫描 ZigZag扫描，将二维的系...

mmlf
2018/02/07
0
0

peterli
2012/08/25
416
0

mmlf
2018/02/05
0
0
[CCFwithAxin]201412-2 Z字形扫描（类似蛇形矩阵）

XiyouLinux_Kangyijie
2017/11/01
0
0
[LeetCode] Zigzag Iterator 之字形迭代器

Given two 1d vectors, implement an iterator to return their elements alternately. For example, given two 1d vectors: v1 = [1, 2]v2 = [3, 4, 5, 6] By calling next repeatedly unti......

2017/12/15
0
0

ls_cherish

4
0
redis 学习2

2
0
Spring boot 静态资源访问

0. 两个配置 spring.mvc.static-path-patternspring.resources.static-locations 1. application中需要先行的两个配置项 1.1 spring.mvc.static-path-pattern 这个配置项是告诉springboo......

moon888

4
0
hash slot（虚拟桶）

4
0
Kafka 原理和实战

vivo互联网技术

24
0