首页 > 试题广场 >

Grading

[编程题]Grading
  • 热度指数:9890 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    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 than one 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.
示例1

输入

20 2 15 13 10 18

输出

14.0
while True:
    try:
        P,T,G1,G2,G3,GJ=map(int,input().strip().split(' '))
        if abs(G1-G2)<=T:
            result=(G1+G2)/2
        else:
            if min(G1,G2)<=G3:
                result=(min(G1,G2)+G3)/2
            elif min(G1,G2)<=G3<=max(G1,G2):
                result=max(G1,G2,G3)
            else:
                result=GJ
        print('%.1f'%result)
    except:
        break
编辑于 2019-07-29 15:30:11 回复(0)
输入:给出6个数占据一条包含六个正整数的行:P,T,G1,G2,G3和GJ,如问题中所述。保证所有等级都有效,即在[0,P]区间内。
输出:一个数,精确到小数点后一位
  1. 如果G1、G2的差值小于T输出G1、G2的平均值
  2. 否则,如果G3在G1、G2的最小值范围内,则输出和G3和min(G1,G2)的平均值
  3. 否则,如果G3在G1、G2之间的范围内,则输出G1、G2、G3三个的最大值
  4. 否则,输出GJ
while True:
    try:
        grades = list(map(int,input().split()))
        if abs(grades[2]-grades[3]) <= grades[1]:
            print(round(sum(grades[2:4])/2,1))
        elif grades[4] <= min(grades[2:4]):
            print(round((grades[4] + min(grades[2:4]))/2, 1))
        elif grades[4] <= max(grades[2:4]):
            print(round(max(grades[2:5])),1)
        else:
            print(round(grades[5],1))
    except Exception:
        break
编辑于 2018-09-27 14:39:09 回复(1)
try:
    while 1:
        P, T, G1, G2, G3, GJ = map(int, raw_input().split())
        if abs(G1 - G2) <= T:
            result = (G1 + G2) / 2.0
        elif (abs(G3 - G1) <= T and abs(G3 - G2) <= T):
            result = max([G1, G2, G3])
        elif (abs(G3 - G1) > T and abs(G3 - G2) > T):
            result = GJ
        else:
            if abs(G3 - G1) > abs(G3 - G2):
                result = (G3 + G2) / 2.0
            else:
                result = (G3 + G1) / 2.0
        print '%.1f' % result
except:
    pass

发表于 2016-12-29 16:20:35 回复(0)

问题信息

难度:
4条回答 4153浏览

热门推荐

通过挑战的用户

查看代码