腾讯笔试第三题
import java.util.Scanner;
public class box {
public static void main(String[] args) {
Scanner in = new Scanner(System.in
);
int rooms = in.nextInt();
int works = Integer.valueOf(in.nextLine().trim());
int allTime = 1;
int preworks = 0;
String [] allBox = in.nextLine().split(" ");
for(int i = 0; i < allBox.length; i++){
int a = Integer.valueOf(allBox[i]);
if(works >a){
allTime += 1;
works -= a;
preworks += a;
}else{
a -= works;
works += preworks;
//余数
int b = a % works;
if( b != 0 ){
allTime += a/works+2;
works -= b;
preworks = b;
}else {
allTime += a/works+2;
preworks = 0;
}
}
}
System.out.println(allTime);
}
public class box {
public static void main(String[] args) {
Scanner in = new Scanner(System.in
);
int rooms = in.nextInt();
int works = Integer.valueOf(in.nextLine().trim());
int allTime = 1;
int preworks = 0;
String [] allBox = in.nextLine().split(" ");
for(int i = 0; i < allBox.length; i++){
int a = Integer.valueOf(allBox[i]);
if(works >a){
allTime += 1;
works -= a;
preworks += a;
}else{
a -= works;
works += preworks;
//余数
int b = a % works;
if( b != 0 ){
allTime += a/works+2;
works -= b;
preworks = b;
}else {
allTime += a/works+2;
preworks = 0;
}
}
}
System.out.println(allTime);
}
}
各位大神看下,这个能AC吗,没来得及测
#腾讯##笔试题目#