zoukankan      html  css  js  c++  java
  • 201413-2 Z字形扫描

    实现

    #include <cstdio>
    
    #define MAXN 0x1ff
    
    int directions[4][2] = {
        {0,1},  // right
        {1,-1}, // left and down
        {1,0},  // down
        {-1,1}  // right and up
    };
    
    int size;
    
    void getDirection(int* dir,int x, int y) {
        if (*dir == 0) {
            if (x == 0) {
                *dir = 1;
            } else {
                *dir = 3;
            }
        } else if (*dir == 1) {
            if (x == size - 1) {
                *dir = 0;
            } else if (y == 0) {
                *dir = 2;
            } else {
                *dir = 1;
            }
        } else if (*dir == 2) {
            if (y == 0) {
                *dir = 3;
            } else {
                *dir = 1;
            }
        } else {
            if (y == size - 1) {
                *dir = 2;
            } else if (x == 0) {
                *dir = 0;
            } else {
                *dir == 3;
            }
        }
    }
    
    int map[MAXN][MAXN];
    
    int main() {
        scanf("%d",&size);
    
        for (int i = 0;i < size;++i) {
            for (int j = 0;j < size;++j) {
                scanf("%d",&map[i][j]);
            }
        }
    
        int x = 0, y = 0,dir = 0;
        for (int i = 0; i < size;++i) {
            for (int j = 0;j < size;++j) {
                printf("%d ",map[x][y]);
                x += directions[dir][0];
                y += directions[dir][1];
                getDirection(&dir,x,y);
               
            }
        }
    }
    
  • 相关阅读:
    第五课 主引导程序的扩展 下
    C.Candy
    B.大钉骑马走江湖
    A喝酒(北京林业大学校赛)
    HDU 5666 Segment
    南京理工大学第八届校赛题目题解(部分)
    TCO 2016 Round 1B
    139. Word Break
    90. Subsets II
    78. Subsets
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13570533.html
Copyright © 2011-2022 走看看