Create a gist now

Instantly share code, notes, and snippets.

GCJ 2014 - 'Deceitful War' problem solution
package com.bchetty.gcj2014;
import java.util.Iterator;
import java.util.TreeSet;
/**
* GCJ 2014 - 'Deceitful War' problem solution
*
* @author Babji, Chetty
*/
public class DeceitfulWar {
public String findResult(int N, TreeSet<Double> noamisSet1, TreeSet<Double> kensSet1, TreeSet<Double> noamisSet2, TreeSet<Double> kensSet2) {
int normalStrategyResult = 0;
int cheatingStrategyResult = 0;
Iterator<Double> naomisIter1 = noamisSet1.iterator();
while(naomisIter1.hasNext()) {
Double nBlock = naomisIter1.next();
Double kBlock = kensSet1.ceiling(nBlock);
if(kBlock != null) {
naomisIter1.remove();
kensSet1.remove(kBlock);
} else {
kensSet1.remove(kensSet1.first());
normalStrategyResult++;
}
}
int size = N;
while(size > 0) {
Double nBlock = noamisSet2.last();
Double kBlock = kensSet2.last();
if(nBlock > kBlock) {
cheatingStrategyResult++;
noamisSet2.remove(nBlock);
kensSet2.remove(kBlock);
} else {
if(noamisSet2.size() > 1) {
noamisSet2.remove(noamisSet2.first());
kensSet2.remove(kBlock);
}
}
size--;
}
return ("" + cheatingStrategyResult + " " + normalStrategyResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment