- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowplate.java
More file actions
Latest commit
60 lines (54 loc) · 1.22 KB
/
Copy pathThrowplate.java
File metadata and controls
60 lines (54 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
packagecom.test;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;
publicclassThrowplate {
/**
* @author wyl
* 有一口井,井的高度为N,每隔1个单位它的宽度有变化。
* 现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,
* 则圆盘被卡住(恰好等于的话会下去)。
* 盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。
* 盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,
* 求最终落到井内的盘子数量。
* 如图井和盘子信息如下:
井:5 6 4 3 6 2 3
盘子:2 3 5 2 4
*/
publicstaticvoidmain(String[] args) {
List<Integer> list = newArrayList<Integer>();
//生成井
inttmp=0;
intsum=0;
intM=7; //井的層數為M
intN=5; //盤子的個數為N
Scannersc = newScanner(System.in);
for(inti=0;i<M;i++){
tmp=sc.nextInt();
//做下預處理,因爲井的下面肯定比上面部分小
if(i==0){
list.add(tmp);
}else{
list.add(Math.min(tmp, list.get(i-1)));
}
}
System.out.println(list);
for(intj=1;j<=N;j++){
//輸入盤子寬度
tmp = sc.nextInt();
if((M-1)>=0){
while(list.get(M-1)<tmp){
M--;
}
}
if(M>0) {
sum++;
System.out.println("sum--->"+sum);
M--;
}else{
System.out.println(sum);
return;
}
}
}
}