-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCerealSim.java
More file actions
50 lines (49 loc) · 1.25 KB
/
CerealSim.java
File metadata and controls
50 lines (49 loc) · 1.25 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
import java.io.*;
import java.util.Arrays;
public class CerealSim {
public static void main(String[] args) throws IOException
{
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("cereal.in"));
String[] temp = br.readLine().split(" ");
int N = Integer.parseInt(temp[0]);
int M = Integer.parseInt(temp[1]);
int[] sol = new int[N];
boolean[] cowsusing = new boolean[M];
int[][] preferences = new int[N][2];
int first, second;
for (int i = 0; i < N; i++)
{
temp = br.readLine().split(" ");
first = Integer.parseInt(temp[0])-1;
second = Integer.parseInt(temp[1])-1;
preferences[i] = new int[] {first, second};
}
int count = 0;
for (int i = 0; i < N; i++)
{
count = 0;
Arrays.fill(cowsusing, false);
for (int j = i; j < N; j++)
{
if (!cowsusing[preferences[j][0]])
{
cowsusing[preferences[j][0]] = true;
count++;
continue;
}
if (!cowsusing[preferences[j][1]])
{
cowsusing[preferences[j][1]] = true;
count++;
continue;
}
}
sol[i] = count;
}
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("cereal.out")));
for (int el: sol)
pw.println(el);
pw.close();
}
}