-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-jumpclouds.js
54 lines (48 loc) · 1.39 KB
/
3-jumpclouds.js
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
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
function main() {
var n = parseInt(readLine());
c = readLine().split(' ');
c = c.map(Number);
var i; // счетчик
var cr; // текущий номер облака
var mincl; // мин. количество облаков
if ((c[0] == 0) && (c[0] == c[c.length-1])) {
switch(n) {
case 2:
process.stdout.write("1" + "\n");
break;
case 3:
process.stdout.write("1" + "\n");
break;
case 4:
process.stdout.write("2" + "\n");
break;
default:
cr = n - 1;
mincl = 0;
while (cr > 0) {
if (c[cr - 2] == 1) {
cr = cr - 1;
} else {
cr = cr - 2;
}
mincl = mincl + 1;
}
process.stdout.write("" + mincl + "\n");
}
}
}