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.
20 2 15 13 10 18
14.0
#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; } }
#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; }
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
//水题 #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); }
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
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
#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); } } } } }
/* 题目翻译: 描述 为成千上万的研究生入学考试打分是一项艰巨的工作。 设计一个过程以使结果尽可能公平就更难了。 一种方法是将每个考试问题分配给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; }
我的以下代码在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; }
//送分题,就是麻烦一点 #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); } } } }
#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; }
#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; }
#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); } }
#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); } } }
//需要注意的是强制转换一定不要忘记(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; }
#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; }
#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); } }