CodeForces Round #118 - Mushroom Scientists

    咩哈哈~~Round #118 水得只剩防爆的E题了..

    这题A得很神奇...俺只是做了个猜测..写了如下无比猥琐丑陋的代码..居然真给AC了...

     我就是一位一位的确定..大致上是可行的..随着精确位的深入..答案会越来越优...但我发现这样非常不严谨很容易会出错..那么我就在确定一位时给其更长的尝试范围( 如当前要确定0.1上的数..按常规思维..尝试0.0~0.9..而我的尝试是从-5.1~5.1...)...


Program:

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std; 
int a,b,c,s;
double x,y,z,m,X,Y,Z,M;
void get(double k)
{
       double tx,ty,tz;
       int xx,yy;
       tx=X; ty=Y; tz=Z; 
       for (xx=-51;xx<=51;xx++)
          for (yy=-51;yy<=51;yy++)
          { 
                 x=X+xx*k;
                 y=Y+yy*k;
                 if (x<0 || y<0 || x+y>s) continue;   
                 z=s-x-y;
                 m=0;
                 if (a!=0) 
                   if (x>k) m+=a*log(x);
                      else continue;
                 if (b!=0)
                   if (y>k) m+=b*log(y);
                      else continue;
                 if (c!=0)
                   if (z>k) m+=c*log(z); 
                      else continue; 
                 if (m>M+0.00000001)
                 {
                         M=m;
                         tx=x;
                         ty=y;
                         tz=z; 
                 }                 
          }
       X=tx;  Y=ty; Z=tz;
}
int main()
{       
       int i;
       double k;
       scanf("%d%d%d%d",&s,&a,&b,&c);
       M=-1e+100;
       X=Y=Z=0;
       for (x=0;x<=s+0.000001;x+=1)
         for (y=0;y<=s-x+0.000001;y+=1)
         {  
               z=abs(s-x-y);
               m=0;
               if (a!=0) 
                 if (x>0.000001) m+=a*log(x);
                    else continue;
               if (b!=0)
                 if (y>0.000001) m+=b*log(y);
                    else continue;
               if (c!=0)
                 if (z>0.000001) m+=c*log(z); 
                    else continue;
               if (m>M+0.000001)
               {
                       M=m;
                       X=x;
                       Y=y;
                       Z=z; 
               }
         }
       k=1;
       for (i=1;i<=16;i++)
       { 
               k/=10;
               get(k);
       } 
       printf("%.16lf %.16lf %.16lf\n",X,Y,Z);
       return 0;
}


你可能感兴趣的:(CodeForces Round #118 - Mushroom Scientists)