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);
        }
    
    }
  • 相关阅读:
    关于PowerShell调用Linq的一组实验
    PowerShell创建参考窗口
    Python切图脚本
    11->8
    用Python演奏音乐
    关于Haskell计算斐波那契数列的思考
    傅立叶变换与小波分析
    堆排序(python实现)
    二进制数据表示方式
    oracle数据插入/查询乱码
  • 原文地址:https://www.cnblogs.com/waka401/p/2627349.html
Copyright © 2011-2022 走看看