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

Full text and comments »

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

By zzyzzy12, 14 years ago, In English

180E - Cubes I just pasted C,F in the contest . Both C and F are very easy , and E is the most people passed except C,F. Just now , I got accepted!! According to the input , we can know that if we want to solve it , the program must be O(n) or O(nlogn) . So I followed this thought and got right answer.

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
struct node
{
       int next,w;
}point[200005];
int s[200005],b[200005],last[200005],n,m,k,x,q;
int main()
{      
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
       int t,ans,m,p;
       memset(s,0,sizeof(s)); 
       memset(point,0,sizeof(point));
       memset(b,0,sizeof(b)); 
       scanf("%d%d%d",&n,&m,&k);
       ans=q=0;
       for (t=1;t<=n;t++)
       {
             scanf("%d",&x);
             s[x]++;
             if (!b[x]) 
             {
                    b[x]=t;     // get b[] initial value
                    last[x]=t;   //  get last[] initial value
                    point[t].w=s[x]; // record s[x] in position t
             }else
             if (x!=q)
             {
                    point[last[x]].next=t; // 
                    point[t].w=s[x];       //  record s[x] in position t
                    last[x]=t;            // update last[x] 
             }
             q=x;       
             m=t-b[x]+1;              //    get the length of interval
             while (m-(s[x]-point[b[x]].w+1)>k)  // repeat until delete number isn't bigger than k
             {  
                    b[x]=point[b[x]].next;      // try bigger start point
                    m=t-b[x]+1;                 // get the length of interval
             } 
             if (s[x]-point[b[x]].w+1>ans) ans=s[x]-point[b[x]].w+1;  // update answer
       }
       printf("%d\n",ans);
       return 0;
}

Full text and comments »

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

By zzyzzy12, 14 years ago, In English

My name is Jacob Chou , and I'm a freshman about algorithm . Last night is the first time I enjoy CF's contest , well it's just a start , I'll be studying harder . Even my English is bullshit , I also enjoy make friend with everybody who love algorithm . my E-mail is zzyzzy12@126.com

Full text and comments »

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