题目链接:http://ac.jobdu.com/problem.php?pid=1002
题目分析:
挺简单的,原文英文也挺好理解,太长了,我这里不翻译了=。=
源代码:
#include <iostream>
#include <iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
int P, T, G1, G2, G3, GJ;
double score = 0.0;
while (cin>>P>>T>>G1>>G2>>G3>>GJ)
{
if((G1>P || G1<0) || (G2>P || G2<0) || (G3>P || G3<0) || (GJ>P || GJ<0))
{
break;
}
if (abs(G1 - G2) <= T || abs(G2 - G1) <= T)
{
score = (G1 + G2) / 2.0;
}
else
{
if (abs(G1 - G3) <= T || abs(G3 - G1) <= T)
{
if (abs(G2 - G3) <= T || abs(G3 - G2) <= T) //both
{
if (G1 >= G2)
{
if (G1 >= G3)
{
score = G1; //G1最大
}
else
{
score = G3; //G3最大
}
}
else
{
if (G2 >= G3)
{
score = G2; //G2最大
}
else
{
score = G3; //G3最大
}
}
}
else //either
{
if (abs(G1 - G3) <= abs(G2 - G3))
{
score = (G1 + G3) / 2.0;
}
else
{
score = (G2 + G3) / 2.0;
}
}
}
else if(abs(G2 - G3) <= T || abs(G3 - G2) <= T) //either
{
if (abs(G1 - G3) <= abs(G2 - G3))
{
score = (G1 + G3) / 2.0;
}
else
{
score = (G2 + G3) / 2.0;
}
}
else
{
score = GJ;
}
}
cout.setf(ios::fixed); //按点输出显示
cout<<setprecision(1)<<score<<endl;
}
return 0;
}