我去啊。。这道题断断续续写了两个晚上,算分真是繁琐,各种鸟规则搞来搞去头都绕晕,花了N久把思路理清,然后用JAVA的OOP,最后AC的内存10M多。。JAVA真是坑内存
第一次自以为把题意搞对了,提交WA,最怕这种大代码题WA,然后又没有测试数据的。。只能看别人代码然后对照自己代码一点点找。。一个小时过去了,实在感觉逻辑应该没错,就又跑了一次,发现输入的队名和分数多了一个空格!!!!!,what a fuck!!! ,唉,怪谁呢,只能怪自己粗心,WA查错实在太痛苦了,现在submit的时候都有心理阴影。。特别是那种代码很多的题
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ScoreComp cpp = new ScoreComp();
for (int i = 0; i < n; i++)
{
if (i > 0)
System.out.println();
Team[] allTeam = new Team[sc.nextInt()];
sc.nextLine();
int maxLength = -1;
for (int j = 0; j < allTeam.length; j++)
{
Team tm = new Team();
tm.name = sc.nextLine();
if (tm.name.length() > maxLength)
maxLength = tm.name.length();
allTeam[j] = tm;
}
int m = sc.nextInt();
for (int j = 0; j < m; j++)
{
Contest contest = new Contest();
Map<Integer, TeamInContest> map = getContestTeamInfo(sc);
contest.map = map;
contest.takePartIn = map.size();
contest.maxSovled = 0;
for (int key : map.keySet())
{
int ts = map.get(key).totalSolve;
if (ts > contest.maxSovled)
contest.maxSovled = ts;
}
int a = 2 * contest.takePartIn - 2;
int b = contest.takePartIn - 2;
for (int key : map.keySet())
{
TeamInContest tic = map.get(key);
int p = tic.totalSolve;
double rs = contest.maxSovled == 0 ? 0.0 : p * 1.0d
/ contest.maxSovled;
double score = rs * a / (b + tic.rank);
allTeam[key - 1].totalScore += score;
allTeam[key - 1].totalTakePart++;
}
}
for (Team t : allTeam)
{
t.resultScore = t.totalTakePart == 0 ? 0 : t.totalScore
/ t.totalTakePart;
}
Arrays.sort(allTeam, cpp);
for (Team t : allTeam)
{
System.out.format("%-" + maxLength + "s %.4f\n", t.name,
t.resultScore);
}
}
}
static Map<Integer, TeamInContest> getContestTeamInfo(Scanner sc)
{
int k = sc.nextInt();
Map<Integer, TeamInContest> map = new HashMap<Integer, TeamInContest>();
for (int i = 0; i < k; i++)
{
TeamInContest tic = new TeamInContest();
map.put(sc.nextInt(), tic);
}
int probleams = sc.nextInt();
for (int i : map.keySet())
{
TeamInContest t = map.get(i);
t.solveStatus = new boolean[probleams];
t.penalty = new int[probleams];
}
int runs = sc.nextInt();
sc.nextLine();
for (int i = 0; i < runs; i++)
{
String line = sc.nextLine();
String[] ss = line.split(" ");
int teamNo = Integer.parseInt(ss[0]);
int proNo = ss[1].charAt(0) - 'A';
int time = Integer.parseInt(ss[2]);
char accepted = ss[3].charAt(0);
TeamInContest t = map.get(teamNo);
if (accepted == '+')
{
if (!t.solveStatus[proNo])
{
t.solveStatus[proNo] = true;
t.penalty[proNo] += time;
t.totalSolve++;
}
}
else
{
if (!t.solveStatus[proNo])
t.penalty[proNo] += 20;
}
}
for (int i : map.keySet())
{
TeamInContest t = map.get(i);
for (int j = 0; j < t.solveStatus.length; j++)
{
if (t.solveStatus[j])
t.totalPenalty += t.penalty[j];
}
}
rankTeam(map);
return map;
}
static void rankTeam(Map<Integer, TeamInContest> map)
{
TeamInContest[] array = new TeamInContest[map.size()];
int i = 0;
for (int no : map.keySet())
{
array[i++] = map.get(no);
}
TeamComp tc = new TeamComp();
Arrays.sort(array, tc);
array[0].rank = 1;
for (int j = 1; j < array.length; j++)
{
if (tc.compare(array[j], array[j - 1]) == 0)
array[j].rank = array[j - 1].rank;
else
array[j].rank = j + 1;
}
}
static class TeamComp implements Comparator<TeamInContest>
{
public int compare(TeamInContest o1, TeamInContest o2)
{
if (o1.totalSolve != o2.totalSolve)
return o2.totalSolve - o1.totalSolve;
else
return o1.totalPenalty - o2.totalPenalty;
}
}
static class ScoreComp implements Comparator<Team>
{
public int compare(Team o1, Team o2)
{
if (o2.resultScore > o1.resultScore)
return 1;
else if (o1.resultScore > o2.resultScore)
return -1;
else
return 0;
}
}
}
class Team
{
String name;
double totalScore = 0;
int totalTakePart = 0;
double resultScore;
}
class Contest
{
Map<Integer, TeamInContest> map;
int maxSovled;
int takePartIn;
Map<Integer, Double> score;
}
class TeamInContest
{
boolean[] solveStatus;
int[] penalty;
int totalPenalty = 0;
int totalSolve = 0;
int rank;
}