-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay82
65 lines (50 loc) · 1.88 KB
/
Day82
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
//Day82
//A. Games
//https://codeforces.com/problemset/problem/268/A
import java.util.Scanner;
public class UniformCounter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] uniforms = new int[n][2];
for (int i = 0; i < n; i++) {
uniforms[i][0] = scanner.nextInt(); // Home color
uniforms[i][1] = scanner.nextInt(); // Guest color
}
int count = 0;
// Count the number of times a host team wears its guest uniform
for (int i = 0; i < n; i++) { // Host team
for (int j = 0; j < n; j++) { // Guest team
if (i != j) { // Ensure they are not the same team
if (uniforms[i][0] == uniforms[j][1]) { // Home color matches guest color
count++;
}
}
}
}
System.out.println(count);
scanner.close();
}
}
//77. Combinations
//public class Solution {
public List<List<Integer>> combine(int n, int k) {
List<List<Integer>> result = new ArrayList<>();
backtrack(result, new ArrayList<>(), n, k, 1);
return result;
}
private void backtrack(List<List<Integer>> result, List<Integer> tempList, int n, int k, int start) {
// If the combination is complete
if (tempList.size() == k) {
result.add(new ArrayList<>(tempList));
return;
}
// Explore further numbers
for (int i = start; i <= n; i++) {
tempList.add(i); // Add number to current combination
backtrack(result, tempList, n, k, i + 1); // Move to the next number
tempList.remove(tempList.size() - 1); // Backtrack and remove the last added number
}
}
}
//