woensdag 1 augustus 2007

Finally Yellow

Two of my best matches in div I happened to be 3.a.m ones, and this is one of them :P. Ranked 131th in division 1, with 103+ additional rating points, finally I become Yellow !.

All thanks to this brute O(n^3) force (but I am not ashamed, Petr's look more or less similar :P):

import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class WhiteHats
{
public int whiteNumber(int[] c)
{
sort(c);
int n = c.length;
for(int w=0;w<=n;w++){
int cur[] = new int[n];
int cnt[] = new int[n];
for(int i=0;i<w;i++) cur[i] = 1;

for(int i=0;i<n;i++)
for(int j=0;j<n;j++) if(j!=i)
cnt[i] += cur[j];

sort(cnt);
boolean ok = true;
for(int i=0;ok && i<n;i++) ok = (cnt[i] == c[i]);
if(ok) return w;
}
return -1;
}
}


I hope I could stay yellow or even better increasing :)

Geen opmerkingen: