Anyone interested in helping me with this code?

Anyone interested in helping me with this code?

Post by Xerxes198 » Sun, 10 Sep 2006 09:27:22


am trying to figure out this problem from TopCoder.com. The problem
is from a past competition that I am just trying to solve to help
increase my knowledge of Java. The problem is as follows:

"Just before a chess match between two teams, each team's coach
secretly determines an ordering of his team's players. The first
players in each team then get to play against each other, the second
players in each team play against each other, etc. The team with the
most wins will win the match.
You are the coach for one of the teams, and you have somehow managed to
find out the order of the players in the other team. Based on that, you
want to order your players so that your team's expected score is
maximized to your advantage. The expected score of a single game can be
calculated by the following formula (which is directly derived from how
the international chess rating system works):
EA = 1 / (1 + 10 (RB - RA)/400)

EB = 1 / (1 + 10 (RA - RB)/400)
where RA and RB are the ratings of player A and B, and EA and EB are
the expected scores for each player. For instance, if RA is 2432 and RB
is 2611, the expected score for player A is 1 / (1 + 10 179/400) =
0.263005239459. The expected score for a team is the sum of the
expected scores for the players in that team.
To make things a bit more complicated, the players in a team must be
ordered such that a player with rating x plays before all players with
rating strictly less than x - lim, where lim is a given non-negative
integer. For example, if lim is 100, a player with rating 2437 must
play before a player with rating 2336 but not necessarily before a
player with rating 2337.
Create a class ChessMatch containing the method bestExpectedScore which
takes a int[] teamA, the ratings of your players (in no particular
order); a int[] teamB, the ratings of your opponent's players in the
order they will play; and an int lim, the limit determining how freely
you can order your players. You can assume that your opponent's players
will be ordered in accordance with lim. The method should return a
double, your team's expected score if you order your players
optimally."

And I have written the following code so far:

public class ChessMatch
{

public void main(String[] args)
{
}
public double bestExpectedScore(int[] my_team, int[] their_team, int
limit)
{
double bestScore = 0.0;
int[] my_team_ordered = new int[my_team.length];
for (int i=0; i < my_team.length; i++)
{
my_team_ordered[i] = maxInArray(my_team);
for (int x=0; x < my_team.length; x++)
{
if (my_team[x] == my_team_ordered[i])
my_team[x] = 0;
}
}
my_team = my_team_ordered;
int[] is_movable = new int[my_team.length];
int[] not_movable = new int[my_team.length];
for (int i=0; i < is_movable.length; i++)
{
is_movable[i] = 0;
not_movable[i] = 0;
}
for (int i=0; i < my_team.length; i++)
{
for (int j=0; j < my_team.length; j++)
{
if (j > i)
{
if (my_team[i] <= my_team[j] + limit)
{
for (int x = i; x < j+1; x++)
is_movable[x] = 1;
}
}
}
}
int numMovable = 0;
for (int i=0; i < is_movable.length; i++)
numMovable += is_movable[i];
int possibleCombos = 1;
for (int i=numPossibilities; i > 0; i--)
possibleCombos *= i;
if (possibleCombos == 1)
bestScore = ExpectedScore(my_team, their_team);
else
{
//Can't
 
 
 

Anyone interested in helping me with this code?

Post by Xerxes198 » Sun, 10 Sep 2006 09:41:35

Oops I found a mistake already... the numPossiblilities is supposed to
be numMovable