zoukankan      html  css  js  c++  java
  • 洛谷 差分模板提 P2367 语文成绩 JAVA读入优化

    给定N个学生的初试成绩,老师会给第x个学生到第y个学生加z分。问最终学生成绩最小的是多少。

    直接差分,最后一个点一直MLE,最后百度出JAVA读入优化过了

    import java.math.BigInteger;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.StreamTokenizer;
    import java.math.*;
    import java.io.*;
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args) throws IOException {
            StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            int n,p;
            int x,y,z;
            st.nextToken();
            n = (int) st.nval;
            int c[] = new int [n + 5];
            st.nextToken();
            p = (int) st.nval;
            int tmp1,tmp2;
            tmp1 = 0;
            for(int i = 1; i <= n; i++){
                st.nextToken();
                tmp2 = (int) st.nval;
                if(i == 1) {
                    c[i] = tmp2;
                    tmp1 = tmp2;
                    continue;
                }
                c[i] = tmp2 - tmp1;
                tmp1 = tmp2;
            }
            for(int i = 0; i < p; i++){
                st.nextToken();
                x = (int) st.nval;
                st.nextToken();
                y = (int) st.nval;
                st.nextToken();
                z = (int) st.nval;
                c[x] += z;
                c[y+1] -= z;
            }
            int Min = c[1];
            for(int i= 2;i <= n;i++){
                c[i] += c[i-1];
                if(c[i]< Min) Min=c[i];
            }
            System.out.println(Min);
        }
    }
  • 相关阅读:
    python list添加元素的几种方法
    Python ---- list和dict遍历
    python 之 collections
    python list 中元素的统计与排序
    pandas dataframe 读取 xlsx 文件
    Python 缓存机制与 functools.lru_cache(zz)
    pip 使用
    python 中的异常处理
    python 时间日期处理
    python read txt file
  • 原文地址:https://www.cnblogs.com/hznumqf/p/13190907.html
Copyright © 2011-2022 走看看