Sunday, September 15, 2013

Topcoder SRM 586 DIV 2 L1 TeamsSelection

// Topcoder SRM 586 DIV 2 L1 TeamsSelection

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class TeamsSelection {
public static void main(String[] args) {
TeamsSelection obj = new TeamsSelection();
System.out.println(
obj.simulate(
null,
null
));
}

public String simulate(int[] preference1, int[] preference2) {
String result = "";
HashSet<Integer> selected = new HashSet<Integer>();
HashSet<Integer> selectedBy1 = new HashSet<Integer>();
int N = preference1.length;
for (int i = 0; i < N; i++) {
for (int j1 = 0; j1 < N; j1++) {
if (!selected.contains(preference1[j1])) {
selected.add(preference1[j1]);
selectedBy1.add(preference1[j1]);
break;
}
}
for (int j2 = 0; j2 < N; j2++) {
if (!selected.contains(preference2[j2])) {
selected.add(preference2[j2]);
break;
}
}
}
for (int i = 1; i <= N; i++) {
if (selectedBy1.contains(i))
result += "1";
else
result += "2";
}
return result;
}
}

No comments:

Post a Comment