zzyzzy12's blog

By zzyzzy12, 14 years ago, In English

my code is very very ugly and I can't belief my program got Accepted .

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

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
14 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

What useful information did you want to convey with this post?