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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值