Ground water issues - changes to static (puzzles)

描述
学校里有一个水房,水房里一共装有m 个龙头可供同学们打开水,每个龙头每秒钟的 供水量相等,均为1。 现在有n 名同学准备接水,他们的初始接水顺序已经确定。将这些同学按接
水顺序从1 到n 编号,i 号同学的接水量为wi。接水开始时,1 到m 号同学各占一个水龙头,
并同时打 开水龙头接水。当其中某名同学j 完成其接水量要求wj 后,下一名排队等候接水的
同学k 马上接替j 同学的位置开始接水。这个换人的过程是瞬间完成的,且没有任何水的浪费
。即 j 同学第x 秒结束时完成接水,则k 同学第x+1 秒立刻开始接水。若当前接水人数n’不
足m, 则只有n’个龙头供水,其它m−n’个龙头关闭。 现在给出n 名同学的接水量,按照上述

看到这个问题一开始有点懵逼,学生都是动态的,经过几次草稿纸上画图(建议大家做做编程的时候,多在草稿纸上画来画去)
以下是我各人的数量
第一步:先输入多少个学生的数量 如5个接水规则,问所有同学都接完水需要多少秒。
输入描述:
  第1 行2 个整数n 和m,用一个空格隔开,分别表示接水人数和龙头个数。 第2 行n 个整数w1、w2、……、wn,每两个整数之间用一个空格隔开,wi 表示i 号同学的接水量。
 5 3
 4 4 1 2 1
输出描述:
输出只有一行,1 个整数,表示接水所需的总时间。
输出样例:
4

See this issue to force a start bit ignorant, students are dynamic, after several draft paper on the drawing (suggest that you do some programming, multi painting to painting to go on rough paper)
The following is my number everyone's
first step: to enter the number of how many students as 5
Ground water issues - changes to static (puzzles)
step number as input taps three
Ground water issues - changes to static (puzzles)
third step: enter the number of each person to draw water as 44,121
Ground water issues - changes to static (puzzles)
Ground water issues - changes to static (puzzles)
Ground water issues - changes to static (puzzles)
third fastest to complete the substitutions then tap water
Ground water issues - changes to static (puzzles)
when the third tap second student then finished the first two taps of the students not completed
Ground water issues - changes to static (puzzles)
i.e., to a maximum value after a general idea that a student each value processing to the smallest value Riga, processes all students i.e. the total time spent

        import java.util.Scanner;
        public class Main{
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                Scanner sca = new Scanner(System.in);
                int m, n;
                m = sca.nextInt();
                 n = sca.nextInt();
                int arr[]  =  new int [m];
                int arr1[] = new int[n];
                for (int i = 0; i < m; i++) {
                    arr[i] = sca.nextInt();
                    }
                    for(int i = 0 ; i < m; i++) {
                    int temp1 = arr1[0], temp2 = 0;
                    for (int i1 = 0; i1 < n; i1++) {
                        if (temp1 > arr1[i1]) {
                            temp1 = arr1[i1];
                            temp2 = i1;
                        }
                    }
                    arr1[temp2] += arr[i];
                }
                int temp = arr1[0];
                for (int i = 1; i < n; i++) {
                    if (temp < arr1[i]) 
                        temp = arr1[i];
                }
                System.out.println(temp);  
            }
        }

Guess you like

Origin blog.51cto.com/14429166/2416805