Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
小沃沃一共參加了 4 門考試既峡,每門考試滿分 100 分陈辱,最低 0 分瘸右,分數(shù)是整數(shù)。
給定四門考試的總分痢畜,請問在最優(yōu)情況下俐填,四門課績點的和最高是多少蝴光?
分數(shù)與績點之間的對應關(guān)系如下:
95~100 4.3
90~94 4.0
85~89 3.7
80~84 3.3
75~79 3.0
70~74 2.7
67~69 2.3
65~66 2.0
62~64 1.7
60~61 1.0
0~59 0
Input
第一行一個正整數(shù) test(1≤test≤401) 表示數(shù)據(jù)組數(shù)。
接下來 test 行堕仔,每行一個正整數(shù) x 表示四門考試的總分 (0≤x≤400)。
Output
對于每組數(shù)據(jù)晌区,一行一個數(shù)表示答案摩骨。答案保留一位小數(shù)通贞。
Sample Input
2
0
400
Sample Output
0.0
17.2
分析
為了使績點最優(yōu),每個分數(shù)段直接選擇最低的分數(shù)即可恼五。然后枚舉可能出現(xiàn)的分數(shù)分布情況昌罩,選出績點最高的值。
C++代碼
#include<iostream>
#include<algorithm>
using namespace std;
int a[11]={0,60,62,65,67,70,75,80,85,90,95};
double b[11]={0,1.0,1.7,2.0,2.3,2.7,3.0,3.3,3.7,4.0,4.3};
int main()
{
int test,score;
double result=0.0;
cin>>test;
while(test--)
{
cin>>score;
for(int i=0;i<11;i++)
{
for(int j=0;j<11;j++)
{
for(int k=0;k<11;k++)
{
for(int m=0;m<11;m++)
{
if(a[i]+a[j]+a[k]+a[m]<=score)result=max((double)result,b[i]+b[j]+b[k]+b[m]);
}
}
}
}
printf("%.1f\n",result);
}
return 0;
}