首页 > 试题广场 >

Grading

[编程题]Grading
  • 热度指数:9878 时间限制: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
简单,读懂题目就OK啦
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
    int p,t;
    int g1,g2,g3,g4;
    while(cin>>p>>t>>g1>>g2>>g3>>g4){  
        double score;
        if(abs(g1-g2)<=t)
            score=(double)(g1+g2)/2;
        else{
            if(abs(g3-g1)<=t&&abs(g3-g2)>t)
                score=(double)(g3+g1)/2;
            else if(abs(g3-g2)<=t&&abs(g3-g1)>t)
                score=(double)(g3+g2)/2;
            else if(abs(g3-g2)<=t&&abs(g3-g1)<=t){
                int temp=g3>g2?g3:g2;
                score=temp>g1?temp:g1;
            }
            else score=g4;
        }
        cout<<fixed<<setprecision(1)<<score<<endl;
    }
}

发表于 2019-02-10 19:30:20 回复(0)
#include<stdio.h>
(737)#include<math.h>
int main()
{
    int  P,T,G1,G2,G3,GJ;
    float grade;
    while(scanf("%d%d%d%d%d%d",&P,&T,&G1,&G2,&G3,&GJ)!=EOF)
    {
        if(abs(G1-G2)<=T)
            grade=(G1+G2)*1.0/2;
        else
        {
            
            if(abs(G1-G3)<=T&&abs(G3-G2)>T)
                grade=(G1+G3)*1.0/2;
            if(abs(G2-G3)<=T&&abs(G3-G1)>T)
                grade=(G2+G3)*1.0/2;
            if(abs(G1-G3)<=T&&abs(G2-G3)<=T)
            {
               grade=G1;
               if(G2>grade) grade=G2;
               if(G3>grade) grade=G3;
            }
            if(abs(G1-G3)>T&&abs(G2-G3)>T)
                grade=GJ;
        }
        printf("%.1f\n",grade);
    }
    return 0;
}

发表于 2020-03-28 20:32:18 回复(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)
//水题
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int p,t,g1,g2,g3,gj;
    cin>>p>>t>>g1>>g2>>g3>>gj;
    double sco;
    if(abs(g1-g2)<=t)
        sco=(g1+g2)*1.0/2;
    else
    {
        if(abs(g1-g3)<=t&&abs(g2-g3)<=t)
        {
            sco=max(max(g1,g2),g3);
        }
        else if(g3!=g1&&abs(g1-g3)<=t||abs(g2-g3)<=t&&g3!=g2)
        {
            if(abs(g2-g3)<abs(g1-g3))
                sco=(g2+g3)*1.0/2;
            else
                sco=(g1+g3)*1.0/2;

        }
        else if(abs(g1-g3)>t&&abs(g2-g3)>t)
        {
            sco=gj;
        }
    }
    printf("%0.1f\n",sco);
}

发表于 2018-03-17 21:08:54 回复(0)
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)
def m(a, b):
    if a > b:
        return a
    else:
        return b
def m3(a, b, c):
    s = []
    s.append(a)
    s.append(b)
    s.append(c)
    return max(s)

def Grading(p, t, g1, g2, g3, gj):
    if abs(g1-g2) <= t:
        return round(((g1+g2) / 2), 1)
    else:
        if abs(g1-g3) <= t and abs(g2-g3) <= t:
            return m3(g1, g2, g3)

        elif abs(g1-g3) <= t and abs(g1-g3) > t&nbs***bsp;abs(g1-g3) > t and abs(g1-g3) <= t:
            k = m(abs(g1-g3), abs(g2-g3))
            return round(k + g3 +g3, 1)
        
        else:
            return gj

while True:
    try:
        p, t, g1, g2, g3, gj = map(int, input().split())
        res = Grading(p, t, g1, g2, g3, gj)
        print(res)
    except:
        break

编辑于 2024-03-23 23:26:54 回复(0)
#include <stdio.h>
#include <math.h>


 main(){
	float g1,g2,g3,gj,t,p;
	

	while(scanf("%f %f %f %f %f %f",&p,&t,&g1,&g2,&g3,&gj)!=EOF){
		float avg=(g1+g2)/2;
		float max,x1,x2,x3;
			if(g1>g2&&g1>g3){
		max=g1;
	}else if(g2>g1&&g2>g3){
		max=g2;
	}else if(g3>g1&&g3>g2){
		max= g3;
	}
		if(abs(g1-g2)<=t)
		{
			printf("%.1f",avg);
		}else 
		{
		if(abs(g3-g1)<=t&&abs(g3-g2)<=t){
			
			printf("%.1f",max);
		}else if(abs(g3-g1)>t&&abs(g3-g2)>t)
		{
			printf("%.1f",gj);
		}else{
			x1=abs(g3-g1);
			x2=abs(g3-g2);
			if(abs(x1-t)<abs(x2-t)){
				printf("%.1f",(g3+g1)/2);
			}else{
					printf("%.1f",(g3+g2)/2);
			}
		}
	}
}

}

 

编辑于 2024-03-08 21:23:53 回复(0)
/*
题目翻译:
描述
为成千上万的研究生入学考试打分是一项艰巨的工作。
设计一个过程以使结果尽可能公平就更难了。
一种方法是将每个考试问题分配给3名独立专家。
如果双方意见不一致,请法官做出最终决定。
现在你被要求编写一个程序来帮助这个过程。
对于每个问题,都有一个满分P和一个公差T(<P)。
评分规则是:
•一个问题将首先分配给两名专家,以获得G1和G2。
如果差值在公差范围内,即|G1-G2|≤T,则该问题的评分为G1和G2的平均值。
•如果差值超过T,第三位专家将给出G3。
•如果G3在G1或G2的公差范围内,但不是两者都在,则此问题的评分将是G3和最接近评分的平均值。
•如果G3与G1和G2都在公差范围内,则该问题的评分将是三个评分中的最大评分。
•如果G3在G1和G2都不在公差范围内,则法官将给出最终评分GJ。
输入描述:
每个输入文件可能包含多个测试用例。
如问题中所述,每种情况都占用一行,其中包含六个正整数:P、T、G1、G2、G3和GJ。
保证所有评分都是有效的,即在区间[0,P]内。
输出描述:
对于每个测试用例,您应该在一行中输出问题的最终评分。答案必须精确到小数点后1位。
*/
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
    int p, t;
    float g1, g2, g3, gj;
    while (cin >> p >> t >> g1 >> g2 >> g3 >> gj) {
        float final;    //最终评分
        if (abs(g1 - g2) <= t) {
            final = (g1 + g2) / 2;
        } else {
            if (abs(g1 - g3) <= t && abs(g2 - g3) > t) {
                final = (g1 + g3) / 2;
            } else if (abs(g1 - g3) > t && abs(g2 - g3) <= t) {
                final = (g2 + g3) / 2;
            } else if (abs(g1 - g3) <= t && abs(g2 - g3) <= t) {
                final = max(max(g1, g2), g3);
            } else {
                final = gj;
            }
        }
        cout << setiosflags(ios::fixed) << setprecision(1) << final << endl;
    }
    return 0;
}

编辑于 2024-02-03 12:55:13 回复(0)
TMD系列这个题目意思都表述不清楚

编辑于 2024-01-25 15:32:30 回复(0)
我的以下代码在IDE中运行是完全符合要求的,输出结果也完全一样,可是牛客网上过不去,这是不是别太死板了#include<stdio.h> #include <math.h>  float max(float x,float y,float z){float M;M=(x>y)?x:y;M=(M>z)?M:z;return M;
}int main() {float P,T;while(scanf("%f %f",&P,&T)!=EOF&&T<=P){float G1,G2,G3,Gj;while(scanf("%f %f",&G1,&G2)!=EOF){if(fabsf(G1-G2)<=T){
                printf("%.1f",(G1+G2)/2);
            }else{
                scanf("%f",&G3);if((fabsf(G1-G3)<=T)&&(fabsf(G2-G3)<=T)){
                    printf("%.1f",max(G1,G2,G3));break;
                }else if(fabsf(G1-G3)<=T){
                    printf("%.1f",(G1+G3)/2);
                }else if(fabsf(G2-G3)<=T){
                    printf("%.1f",(G2+G3)/2);
                }else{
                    scanf("%f",&Gj);
                    printf("%.1f",Gj);
                }
            }
        }
    }return 0;
}
编辑于 2024-01-20 03:47:43 回复(0)
//送分题,就是麻烦一点
#include "stdio.h"
#include "math.h"
#include "algorithm"
using namespace std;

int main(){
    double F,T,G1,G2,G3,GJ;//full-mark,tolerance
    while (scanf("%lf%lf%lf%lf%lf%lf",&F,&T,&G1,&G2,&G3,&GJ) != EOF){
        double difference1 = fabs(G1-G2);
        if(difference1 <= T){
            printf("%.1lf\n",(G1+G2)/2);
            continue;
        } else {
            double difference2 = G3-G1;
            double difference3 = G3-G2;
            if(difference2 <= T && difference3 <= T){
                double max = G1>G2?G1:G2;
                max = max>G3?max:G3;
                printf("%.1lf\n",max);
                continue;
            } else if (difference2 <= T || difference3 <= T){
                if (fabs(G3-G1) < fabs(G3-G2)){
                    printf("%.1ld\n",(G3+G1)/2);
                    continue;
                } else{
                    printf("%.1ld\n",(G3+G2)/2);
                    continue;
                }
            } else{
                printf("%.1lf\n",GJ);
            }
        }
    }
}

发表于 2023-03-26 19:46:36 回复(0)
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double p,t,g1,g2,g3,gj;
    while(cin>>p>>t>>g1>>g2>>g3>>gj){
        if(abs(g1-g2)<=t){
            printf("%.1lf\n",(g1+g2)/2);
        }
        else{
            if(abs(g3-g1)<=t&&abs(g3-g2)<=t){
                double temp=max(g1,g2);
                temp=max(temp,g3);
                printf("%.1lf\n",temp);
            }
            else if(abs(g3-g1)<=t){
                printf("%.1lf\n",(g1+g3)/2);
            }
            else if(abs(g3-g2)<=t){
                printf("%.1lf\n",(g2+g3)/2);
            }
            else{
                printf("%.1lf\n",gj);
            }
        }
    }
    return 0;
}

发表于 2023-03-26 09:51:22 回复(0)
#include <iostream>
#include <iomanip>
using namespace std;

double abs_double(double N)
{
    return (N < 0) ? (-N) : (N);
}

double max(double A, double B, double C)
{
    double MAX = A;
    if (B > MAX)
        MAX = B;
    if (C > MAX)
        MAX = C;
    return MAX;
}

double cal(double P, double T, double G1, double G2, double G3, double GJ)
{
    // 分数计算
    if (abs_double(G1 - G2) <= T)
        return (G1 + G2) / 2;

    else
    {
        if ((abs_double(G3 - G1) <= T) && (abs_double(G3 - G2) <= T))
            return max(G1, G2, G3);

        else if ((abs_double(G3 - G1) > T) && (abs_double(G3 - G2) > T))
            return GJ;

        else
        {
            if (abs_double(G3 - G2) > abs_double(G3 - G1))
                return (G3 + G1) / 2;
            else
                return (G3 + G2) / 2;
        }
    }
}

int main()
{
    double P, T;
    double G1, G2, G3, GJ;

    cin >> P >> T;
    cin >> G1 >> G2 >> G3 >> GJ;

    double Result = cal(P, T, G1, G2, G3, GJ);
    cout.setf(ios::fixed);
    cout.precision(1);
    cout << Result << endl;
}

发表于 2023-02-08 23:04:41 回复(0)
#include <stdio.h>

float Absolute(float n1, float n2) {
    if (n1 > n2) {
        return n1 - n2;
    }
    return n2 - n1;
}
float average(float n1, float n2) {
    return (n1 + n2) / 2;
}
float max(float n1, float n2) {
    if (n1 >= n2) {
        return n1;
    }
    return n2;
}
int main() {

    float G1, G2, G3, Gj = 0;
    float P, T = 0;
    scanf("%f %f", &P, &T);
    scanf("%f %f", &G1, &G2);
    if (Absolute(G1, G2) <= T) {
        float res = average(G1, G2);
        printf("%.1f\n", res);
    } else {
        scanf("%f", &G3);
        if ((Absolute(G3, G1) <= T && Absolute(G3, G2) > T) || (Absolute(G3, G1) > T &&
                Absolute(G3, G2) <= T)) {
            if (Absolute(G3, G1) > Absolute(G3, G2)) {
                printf("%.1f\n", average(G3, G2));
            } else {
                printf("%.1f\n", average(G3, G1));

            }
        } else if (Absolute(G3, G1) <= T && Absolute(G3, G2) <= T) {
            float res = max(G3, G1);
            res = max(res, G2);
            printf("%.1f\n", res);
        } else if (Absolute(G3, G1) > T && Absolute(G3, G2) > T) {
            scanf("%f", &Gj);
            printf("%.1f\n", Gj);
        }
    }

    return 0;
}
发表于 2023-01-26 10:22:48 回复(0)
看似是机试,实则是英语笔试
#include<iostream>
#include<cmath>
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

int main(){
    int P,T,G1,G2,G3,GJ;
    while(scanf("%d%d%d%d%d%d",&P,&T,&G1,&G2,&G3,&GJ)!=EOF){
        double grade;//最终得分
        if(abs(G1-G2)<=T){
            grade=(G1+G2)/2.0;//误差合理取平均值
        }
        else{
            int low=min(G1,G2);
            int high=max(G1,G2);
            if(abs(G3-G1)<=T&&abs(G3-G2)<=T){
                grade=high;
            }
            else if(G3<=low&&low-G3<=T){
                grade=(low+G3)/2.0;
            }
            else if(high<=G3&&G3-high<=T){
                grade=(high+G3)/2.0;
            }
            else{
                grade=GJ;
            }
        }
        printf("%0.1f",grade);
    }
}


发表于 2023-01-16 14:34:39 回复(0)
#include <bits/stdc++.h>
using namespace std;

int P, T, G1, G2, G3, GJ;

int main()
{

    while (cin >> P >> T >> G1 >> G2 >> G3 >> GJ)
    {
        if (abs(G1 - G2) <= T)
            printf("%.1f\n", (G1 + G2) / 2.0);
        else
        {
            if (abs(G3 - G1) <= T && abs(G3 - G2) <= T)
                cout << max(G3, max(G1, G2)) << endl;
            else if (abs(G3 - G1) > T && abs(G3 - G2) > T)
                cout << GJ << endl;
            else if (abs(G3 - G1) <= T)
                printf("%.1f\n", (G3 + G1) / 2.0);
            else
                printf("%.1f\n", (G3 + G2) / 2.0);
        }
    }
}

发表于 2022-07-20 14:29:21 回复(0)
//需要注意的是强制转换一定不要忘记(float)(a+b)/2
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int rever(int a,int b){
    if(a-b>=0){
        return a-b;
    }else{
        return b-a;
    }
}
int main(){
    int p,t,a,b,c,d;
    while(scanf("%d %d %d %d %d %d",&p,&t,&a,&b,&c,&d)!=EOF){
        int maxs=0;
        float x;
        if(rever(a,b)<=t){
            x=(float)(a+b)/2;
            printf("%.1f",x);
        }else{
            if(rever(c,a)>t&&rever(c,b)>t){
                printf("%d",d);
            }else if(rever(c,a)<=t&&rever(c,b)<=t){
                maxs=fmax(a,b);
                maxs=fmax(maxs,c);
                printf("%d",maxs);
            }else{
                if(rever(c,a)<=t){
                    x=(float)(a+c)/2;
                    printf("%.1f",x);
                }else{
                    x=(float)(c+b)/2;
                    printf("%.1f",x);
                }
            }
        }
    }
    return 0;
}

发表于 2022-02-16 14:06:01 回复(0)
#include<iostream>
#include<iomanip>
using namespace std;

int abs(int a,int b){
    int num=0;
    if(a-b<0) num=b-a;
    else num=a-b;
    return num;
}

int main(){
   double P=0,T=0,G1=0,G2=0,G3=0,GJ=0,result=0;
    while(cin>>P){
        cin>>T>>G1>>G2>>G3>>GJ;
        int g12=abs(G1,G2);
        int g13=abs(G1,G3);
        int g23=abs(G2,G3);
        if(g12<=T) result=((G1+G2)/2);
        else if((g13<=T&&g23>T)||(g23<=T&&g13>T)) result=(g12>g23?(G2/2+G3/2):(G1/2+G3/2));
        else if(g13<=T&&g23<=T) result=(G1>G2?(G1>G3?G1:G3):(G2>G3?G2:G3));
        else result=GJ;
    }
    cout<<fixed<<setprecision(1)<<result<<endl;
}
发表于 2022-02-10 15:04:23 回复(0)
#include<iostream>
#include<math.h>

using namespace std;

float P, T, G1, G2, G3, GJ;
float f;

int main(){
    while(scanf("%f%f%f%f%f%f", &P, &T, &G1, &G2, &G3, &GJ) != EOF){
        if(abs(G1 - G2) <= T) f = (G1 + G2) / 2;
        else{
            if(abs(G1 - G3) <= T&&abs(G2 - G3) > T) f = (G1 + G3) / 2;
            else if(abs(G2 - G3) <= T&&abs(G1 - G3) > T) f = (G2 + G3) / 2;
            else if(abs(G1 - G3) <= T&&abs(G2 - G3) <= T) f = max(G1, max(G2, G3));
            else f = GJ;
        }
        printf("%.1f\n", f);
    }
    return 0;
}
发表于 2022-01-21 17:19:32 回复(0)
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    float p, t, g1, g2, g3, gj;
    while(cin >> p >> t >> g1 >> g2 >> g3 >> gj)
    {
        float answer;
        if(abs(g1 - g2) <= t)
            answer = (g1 + g2) / 2;
        else
            if(abs(g3 - g1) <= t && abs(g3 - g1) <= t) 
                answer = g2 > g1? max(g3, g2) : max(g3, g1);
            else if(abs(g3 - g1) <= t || abs(g3 - g1) <= t)
                if(abs(g3 - g1) > abs(g3 - g2))
                    answer = (g3 + g2) / 2;
                else
                    answer = (g3 + g1) / 2;
            else
                answer = gj;
        
        printf("%.1f\n", answer);
    }
}

发表于 2021-08-10 11:35:25 回复(0)

问题信息

难度:
44条回答 4126浏览

热门推荐

通过挑战的用户

查看代码