找不到错的地方,求指教. 不知道是不是格式问题,我觉得格式没问题啦

fishvivfish 2013-03-15 04:49:51
题目:
A competition was just over. It had 3 problems and n players. Each player had an ID number from 1 to n. The final rank was decided by the total score of the 3 problems. The higher the total score was, the higher a player ranked (the smaller the rank number). If two players got the same total score, the one with the smaller ID number got a higher rank. We’ve known for each problem, how much score each player might get if he din’t solve totally wrong (if solved totally wrong, the player got zero in the problem). However, we don’t know whether a player did get score in a problem. For a predicted final rank, you need to judge if the rank is possible.

Input
Input contains several cases. For each case, the first line is an integer n, (n <= 16384) to indicate the number of players, followed by n lines, the ith of which contains three real numbers a, b, c (0<=a, b, c < 1000. a, b and c have 2 decimal places at most.) to respectively indicate the score of each problem Player i might get if he didn’t solve totally wrong. Another line containing n integers follows to indicate the player ID number in the order from rank 1st to rank nth .
The last case is followed by a line containing only a zero.

Output
For each case, if the rank is possible, output the highest possible total score for the player with the lowest rank (calculate to 2 decimal places), otherwise output “No solution" (quotes for clarity).


翻译:
比赛中有3道题,n个参赛人员,每个人都有一个ID,对于每道题,我们知道一个参赛人员如果他没有完全解答错的话应该得的分数,但是如果这道题解答完全错误的话,得零分.排名就是分高的在前面,如果分相等,ID小的在前面.
第一行输入一个整数N,表示几个参赛人员, 接下来N行3个数(每个数最多两位小数),分别有表示各个参赛人员的3道题分别的分数.接着一行是他们的排名.接下来是另外一个测试用例,最后一个测试用例用零表示.

编程看一下每一个测试用例的排名是否可能,可能的话,就输出排名最低的人的可能的最高分(输出要有2位小数),否则输出No solution.
思路
我把各个测试用例的排名放在ArrayList<ArrayList<Integer> > ranks里面,每一测试用例放在ArrayList<ArrayList< ArrayList<Integer> > > cases, 计算每一用例里面每一个人的可能的分数*100,放在ArrayList<ArrayList< TreeSet<Integer> > > possibleScores(8种组合,已经排好序),
最后根据排名,先找到第一个的最高分为max,再找第二个人的最高分,
如果第二个人的最高分小于max的话,max就等于第二个人的最高分.继续下一个人
如果第二个人的最高分==max的话,看一下人员的ID,如果符合要求,max不变,继续下一个人.不符合要求,就在第二个人可能的分数里面找一个小于max的最大值,如果没有,就是No solution,有的话,把这个值赋值给max.继续下一个人.
如果第二个人的最高分>max的话,先看一下第二个人可能的分数里面是否包含max,
包含的话,比较一下ID,
如果符合要求,max不变,继续下一个人;
不符合要求,就在第二个人可能的分数里面找一个小于max的最大值,如果没有,就是No solution,有的话,把这个值赋值给max.继续下一个人;
如果不包含max的话,就在第二个人可能的分数里面找一个小于max的最大值,如果没有,就是No solution,有的话,把这个值赋值给max.继续下一个人.



package testPackage;
import java.util.*;
public class Main {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
short num = 0;//每个测试用例的人数
ArrayList<ArrayList< ArrayList<Integer> > > cases = new ArrayList<ArrayList<ArrayList<Integer> > >();//测试用例
ArrayList<ArrayList< TreeSet<Integer> > > possibleScores = new ArrayList<ArrayList<TreeSet<Integer> > >();//每一人可能的分数
ArrayList<ArrayList<Integer> > ranks = new ArrayList<ArrayList<Integer> >();//排名
while(in.hasNext()){
num = in.nextShort();
if(num == 0)
break;
cases.add(new ArrayList< ArrayList<Integer> >() );
possibleScores.add(new ArrayList<TreeSet<Integer> >() );
ArrayList<ArrayList<Integer> > currentCase = cases.get(cases.size() - 1);
for(int i = 0; i < num; ++i){
currentCase.add(new ArrayList<Integer>());//输入每个人的分数
currentCase.get(i).add((int)(100 * in.nextDouble()));
currentCase.get(i).add((int)(100 * in.nextDouble()));
currentCase.get(i).add((int)(100 * in.nextDouble()));
possibleScores.get(possibleScores.size() - 1).add(new TreeSet<Integer>());
possibleScores.get(possibleScores.size() - 1).get(i).add(0);
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(2));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(1));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(1) + currentCase.get(i).get(2));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(0));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(0) + currentCase.get(i).get(2));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(0) + currentCase.get(i).get(1));
possibleScores.get(possibleScores.size() - 1).get(i).add(currentCase.get(i).get(0) + currentCase.get(i).get(1) + currentCase.get(i).get(2));

}
ranks.add(new ArrayList<Integer>());//输入排名
ranks.get(ranks.size() - 1).add(in.nextInt() - 1);
ranks.get(ranks.size() - 1).add(in.nextInt() - 1);
ranks.get(ranks.size() - 1).add(in.nextInt() - 1);
}
in.close();
Integer max = 0;
for(int i = 0 ; i < cases.size(); ++i){
max = possibleScores.get(i).get(ranks.get(i).get(0)).last();//第一个人的最大值
for(int j = 1 ; j < ranks.get(i).size(); ++j){//一个实例的排行
if(max.compareTo(possibleScores.get(i).get(ranks.get(i).get(j)).last()) > 0){
max = possibleScores.get(i).get(ranks.get(i).get(j)).last();
}else{
if(max.equals(possibleScores.get(i).get(ranks.get(i).get(j)).last())){
if(ranks.get(i).get(j).compareTo(ranks.get(i).get(j - 1)) > 0){//分数相同,小ID在前
continue;
}
}
if((ranks.get(i).get(j).compareTo(ranks.get(i).get(j - 1)) > 0) && possibleScores.get(i).get(ranks.get(i).get(j)).contains(max)){
continue;
}else{
if((max = possibleScores.get(i).get(ranks.get(i).get(j)).lower(max)) == null ){
System.out.println("Case " + (i + 1) + ": " + "No solution");
max = null;
break;
}
}
}
}
if(max != null){
if((int)(max % 100) == 0)
System.out.println("Case " + (i + 1) + ": " + (max / 100) + ".00");
else
if((int)(max % 100) < 10)
System.out.println("Case " + (i + 1) + ": " + (max / 100) + ".0" + (max % 100));
else
System.out.println("Case " + (i + 1) + ": " + (max / 100) + "." + (max % 100));
}
}
}
}
...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishvivfish 2013-03-16
  • 打赏
  • 举报
回复
顶一下,其实觉得很简单.大家不要看了这么长的题目就不看了..求大神

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧