枚举。
枚举每个分段有多少个科目,对每个枚举的状态判断是否满足条件,对满足条件的取其中最大和最小值。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cmath> 5 using namespace std; 6 7 const double eps=1e-8; 8 9 int main (){ 10 int t; 11 int a,n; 12 //cin>>t; 13 scanf ("%d",&t); 14 while (t--){ 15 //cin>>a>>n; 16 scanf ("%d%d",&a,&n); 17 int sum=a*n; 18 double maxn,minn; 19 int mas=n*4,mis=n*8; 20 for (int i=0;i<=n;i++){ 21 for (int j=0;j<=n;j++){ 22 for (int k=0;k<=n;k++){ 23 for (int o=0;o<=n;o++){ 24 if (n>=i+j+k+o&&i*100+j*84+k*79+o*74+(n-i-j-k-o)*69>=sum&&i*85+j*80+k*75+o*70+(n-i-j-k-o)*60<=sum){ 25 int temp=i*8+j*7+k*6+o*5+(n-i-j-k-o)*4; 26 mas=temp>mas?temp:mas; 27 mis=temp<mis?temp:mis;//cout<<i<<" "<<j<<" "<<k<<" "<<o<<" "<<n-i-j-k-o<<":"<<temp*1.0/n/2<<endl; 28 } 29 } 30 } 31 } 32 } 33 minn=1.0*mis/n/2+eps; 34 maxn=1.0*mas/n/2+eps; 35 printf ("%.4f %.4f ",minn,maxn); 36 } 37 return 0; 38 }