zoukankan      html  css  js  c++  java
  • Poj1088

    package poj;
    
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.Arrays;
    import java.util.Iterator;
    import java.util.Scanner;
    
    
    public class Main1088_1 {
    
        static class Node implements Comparable<Node> {
            int x;
            int y;
            int height;
    
            @Override
            public int compareTo(Node o) {
                if (height > o.height)
                    return 1;
                else if (height < o.height)
                    return -1;
                else
                    return 0;
            }
        }
    
        public static void main(String[] args) throws FileNotFoundException {
            Scanner scanner = new Scanner(new BufferedInputStream(
                    new FileInputStream(new File("E:\\input.txt"))));
            int r = scanner.nextInt();
            int c = scanner.nextInt();
            int[][] arr = new int[r][c];
            int[][] res = new int[r][c];
            Node[] list = new Node[r * c];
            int t = 0;
            for (int i = 0; i < r; i++) {
                for (int j = 0; j < c; j++) {
                    arr[i][j] = scanner.nextInt();
                    list[t] = new Node();
                    list[t].x = i;
                    list[t].y = j;
                    list[t++].height = arr[i][j];
                }
            }
            Arrays.sort(list);
            int ans=0;
            for (int i = 0; i < list.length; i++) {
                int x = list[i].x;
                int y = list[i].y;
                int h = list[i].height;
                if (x - 1 >= 0 && arr[x - 1][y] > h&&res[x-1][y]<res[x][y]+1)
                    res[x - 1][y]=res[x][y] + 1;// left
                if (x + 1 < r && arr[x + 1][y] > h&&res[x+1][y]<res[x][y]+1)
                    res[x + 1][y]=res[x][y] + 1;// right
                if (y - 1 >= 0 && arr[x][y - 1] > h&&res[x][y-1]<res[x][y]+1)
                    res[x][y - 1] =res[x][y]  + 1;// up
                if (y + 1 < c && arr[x][y + 1] > h&&res[x][y+1]<res[x][y]+1)
                    res[x][y + 1]=res[x][y]  + 1;// down
                if (ans<res[x][y])  ans=res[x][y];
            }
           System.out.println(ans+1);
        }
    
    }
  • 相关阅读:
    JAVA——return浅析
    JAVA泛型【转】
    C#——WinForm修改密码
    java获取当前时间的方式【转】
    iOS 取得单张系统图片
    iOS UIView的简单渐变效果
    UIView 添加子视图的常用方法
    IOS之UIView的tag学习
    OC学习笔记之属性详解和易错点
    oc对象函数什么时候返回值类型使用instancetype
  • 原文地址:https://www.cnblogs.com/waka401/p/2627349.html
Copyright © 2011-2022 走看看