-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay63
98 lines (70 loc) · 2.37 KB
/
Day63
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//55. Jump Game
//https://leetcode.com/problems/jump-game/description/
class Solution {
public boolean canJump(int[] nums) {
int maxReach = 0;
for (int i = 0; i < nums.length; i++) {
if (i > maxReach) {
return false;
}
maxReach = Math.max(maxReach, i + nums[i]);
if (maxReach >= nums.length - 1) {
return true;
}
}
return false;
}
}
//198. House Robber
//https://leetcode.com/problems/house-robber/description/
class Solution {
public int rob(int[] nums) {
int count = 0;
if(nums.length<2){
return nums[0];
}
int [] dp = new int[nums.length];
dp[0] = nums[0];
dp[1] = Math.max(nums[0], nums[1]);
for (int i = 2; i < nums.length; i++) {
dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 1]);
}
return dp[nums.length - 1];
}
}
//A. Presents
//https://codeforces.com/problemset/problem/136/A
import java.util.Scanner;
public class Apresents {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] gifts = new int[n];
for (int i = 0; i < n; i++) {
int p = sc.nextInt(); // Friend who gave a gift to friend i+1
gifts[p - 1] = i + 1; // Store who received the gift
}
for (int i = 0; i < n; i++) {
System.out.print(gifts[i] + " "); // Output who gave a gift to friend i+1
}
sc.close();
}
}
//B. Drinks
https://codeforces.com/problemset/problem/200/B
import java.util.Scanner;
public class Bdrinks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double totalPercentage = 0.0;
for (int i = 0; i < n; i++) {
int p = sc.nextInt(); // Volume fraction of orange juice in the i-th drink
totalPercentage += p; // Add to the total
}
// Calculate the average percentage of orange juice in the cocktail
double averagePercentage = totalPercentage / n;
System.out.printf("%.12f%n", averagePercentage); // Print with 12 decimal places
sc.close();
}
}