Created
April 24, 2014 11:46
-
-
Save bchetty/11251655 to your computer and use it in GitHub Desktop.
GCJ 2014 - 'Deceitful War' problem solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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