zoukankan      html  css  js  c++  java
  • 【小米OJ-小米兔的轨迹】顺时针蛇形矩形

    import java.util.*;
    
    public class Main {
        static int dr[]={0,1,0,-1};///向左加,向右减
        static int dc[]={1,0,-1,0};///向下加,向上减
        static int arr[][];
        static int n,m;
        public static void main(String [] args) {
            Scanner sc = new Scanner(System.in);
            n = sc.nextInt();
            m = sc.nextInt();
            arr = new int[n + 10][m + 10];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = sc.nextInt();
             System.out.print(arr[0][0]);
             arr[0][0]=-1;
            int t=0;
            int r=0;
            int c=0;
            int j=0;
            while(++t<n*m){
                while(true){
                    int x = r+dr[j];
                    int y = c+dc[j];
                    if(panduan(x,y)&&arr[x][y]!=-1){
                        System.out.print(" "+arr[x][y]);
                        arr[x][y]=-1;
                        r=x;
                        c=y;
                        break;
                    }
                    j++;
                    if(j>=4) j-=4;
                }
            }
        }
        static boolean panduan(int r,int c){
            return r>=0 && r<n && c>=0 &&c<m;
        }
    } 
    

      

    不忘初心,方得始终。只有走过弯路,才更确信当初最想要的是什么。
  • 相关阅读:
    使用DataReader
    使用Dataset
    Command
    Ado.net对象
    集合数据源
    Label 表达式绑定
    输出二进制图像
    Application 可以存储全局变量
    字符串处理
    ?:叫条件运算符
  • 原文地址:https://www.cnblogs.com/wszhu/p/12804895.html
Copyright © 2011-2022 走看看