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);
        }
    
    }
  • 相关阅读:
    .NET/C# 使用 SetWindowsHookEx 监听鼠标或键盘消息以及此方法的坑
    使用UI Automation实现自动化测试--1-4
    使用npm命令下载sass时出现Error: not found: python2
    CentOS上安装Python3
    解决electron打包时,下载超时导致失败
    FJ省队集训2021
    微信小程序自定义封装组件-showModal
    react性能优化
    认识react虚拟Dom
    前端FileReader读取文件信息
  • 原文地址:https://www.cnblogs.com/waka401/p/2627349.html
Copyright © 2011-2022 走看看