题目1002:Grading(九度 Online Judge)
1,真题
题目1002:Grading时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:10721
解决:2735
-
题目描述:
-
Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible. One way is to assign each exam problem to 3 independent experts. If they do not agree to each other, a judge is invited to make the final decision. Now you are asked to write a program to help this process.
For each problem, there is a full-mark P and a tolerance T(<P) given. The grading rules are:
• A problem will first be assigned to 2 experts, to obtain G1 and G2. If the difference is within the tolerance, that is, if |G1 - G2| ≤ T, this problem's grade will be the average of G1 and G2.
• If the difference exceeds T, the 3rd expert will give G3.
• If G3 is within the tolerance with either G1 or G2, but NOT both, then this problem's grade will be the average of G3 and the closest grade.
• If G3 is within the tolerance with both G1 and G2, then this problem's grade will be the maximum of the three grades.
• If G3 is within the tolerance with neither G1 nor G2, a judge will give the final grade GJ.
-
输入:
-
Each input file may contain more thanone test case.
Each case occupies a line containing six positive integers: P, T, G1, G2, G3, and GJ, as described in the problem. It is guaranteed that all the grades are valid, that is, in the interval [0, P].
-
输出:
-
For each test case you should output the final grade of the problem in a line. The answer must be accurate to 1 decimal place.
-
样例输入:
-
20 2 15 13 10 18
-
样例输出:
-
14.0
-
来源:
2011年浙江大学计算机及软件工程研究生真题
2,分析
题目大致意思可以解释为如下:
3个人给一个打分,分数分别为G1,G2,G3。其中满分是P,打分误差是T。
代码判断顺序流程如下
若|G1-G2|<=T,则分数是G1和G2的平均分数
若|G1-G2|>T,则第三人给分G3
若G3和G1在误差范围内,但和G2不在,则分数是G1和G3的平均分数
若G3和G2在误差范围内,但和G1不在,则分数是G2和G3的平均分数
若G3和G1以及G2都在误差范围内,则分数是G1,G2,G3中的最大值
若G3和G1以及G2都不在误差范围内,则分数是系统默认分数GJ
3,答案
import java.util.Scanner;
import java.text.DecimalFormat;
/**
* to test problem_1002
* @author Sunkun
* Date: 2013.09.25
* Memory: 17564KB
* Code Length: 1145B
* Time Consuming: 100MS
*/
public class problem_1002 {
public static void main(String[] args) {
int P,T,G1,G2,G3,GJ;
double result;
int max;
Scanner input = new Scanner(System.in);
// 具体算法,就不详细解释了
while(input.hasNext()){
P = input.nextInt();
T = input.nextInt();
G1 = input.nextInt();
G2 = input.nextInt();
G3 = input.nextInt();
GJ = input.nextInt();
if(T<0 || T>= P || G1<0 || G1>P || G2<0 || G2>P
|| G3<0 || G3>P || GJ<0 || GJ>P){
continue;
}
if(Math.abs(G2-G1) <= T){
result =(float)(G1 + G2)/2;
}else if(Math.abs(G3-G1)<=T && Math.abs(G3-G2)>T){
result = (float)(G1 + G3)/2;
}else if(Math.abs(G3-G2)<=T && Math.abs(G3-G1)>T){
result = (float)(G2 + G3)/2;
}else if(Math.abs(G3-G1)<=T && Math.abs(G3-G2)<=T){
max = G1;
if(G2 > max)
max = G2;
if(G3 > max)
max = G3;
result = max;
}else{
result = GJ;
}
// 格式化输出
DecimalFormat df = new DecimalFormat("0.0");
System.out.println(df.format(result));
}
}
}
4,备注
上述代码直接复制是AC不了的,把类名problem_1002改为Main就可以直接上传通过了:)