zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1567 统计天数

    在这里插入图片描述

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.StringTokenizer;
    
    public class Main {
        private static CustomizedReader cin;
    
        public static void main(String args[]) throws Exception {
            cin = new CustomizedReader(System.in);
            int n = cin.nextInt();
            if(n<=0 || n>Math.pow(10, 7)) {
                return;
            }
            int historyRecord = 0;
            int newRecord = 0;
            int startTemprature = -1;
            int MAX = (int) Math.pow(10, 9);
            for (int i = 0; i < n; i++) {
                int t = cin.nextInt();
                if(t>=0&&t<=MAX) {
                    if(t > startTemprature) {
                        newRecord++;
                        startTemprature = t;
                    }else {
                        if(newRecord > historyRecord) {
                            historyRecord = newRecord;
                        }
                        newRecord = 1;
                        startTemprature = t;
                    }
                }
            }
            if(newRecord > historyRecord) {
                historyRecord = newRecord;
            }
            System.out.println(historyRecord);
        }
    }
    
    class CustomizedReader {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer;
        
        CustomizedReader(InputStream source){
            reader = new BufferedReader(new InputStreamReader(source) );
            tokenizer = new StringTokenizer("");
        }
        
        public String next() {
            while ( ! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                try {
                    tokenizer = new StringTokenizer(reader.readLine() );
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
            
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        
        public double nextLong() {
            return Long.parseLong(next());
        }
        
        public double nextFloat() {
            return Float.parseFloat(next());
        }
        
    }    
    
    
  • 相关阅读:
    POJ3186(KB12-O DP)
    POJ1661(KB12-M DP)
    POJ2533(KB12-N LIS)
    POJ1458(KB12-L LCS)
    HDU1160(KB12-J DP)
    HDU1260(KB12-H DP)
    HDU1114(KB12-F DP)
    HDU1024(DP)
    HDU1074(KB12-D 状态压缩dp)
    天梯赛2016-L2
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076220.html
Copyright © 2011-2022 走看看