hdu5417 Formula method

Source: Internet
Author: User

BCDIV2#52 1001

Test instructions too pit, I thought every time also to calculate machine shut down to meet W value of a variety of take-up operation, every time also to update, think of the scalp tingling, the results of a long time directly abandoned BC, can not go on.

Results just when the problem found in clarification in the 1001 example of the resolution, just know in the moment of closing is allowed to pop the ball, instead of popping the ball. It's a mistake to understand.

The rest is an understanding of mathematical calculations. My math is weak .... It's all holes.

The formula in the code, for me really hard to think Ah ....

I think we must pay attention to the meaning of TT, otherwise it's definitely a pit.

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5 6 using namespacestd;7 intX,y,w,n,num,res,tt,ss;8 9 intMain ()Ten { One      while(cin>>x>>y>>w>>N) { A         if(x<W) { -Res= (n1) * (x+y); -         } the         Else{ -num=1+x/w;//you can eject num balls in x time -Tt=n%num;//tt=0 indicates that the time of the SS X is enough to eject n balls, but there may be surplus; -             //tt! =0 indicates the time required to add tt-1 W outside the time of the SS X +Ss=n/num;//takes a few x long hours -             //cout<< "num" <<num<< "ss" <<ss<< "tt" <<tt<<endl; +             if(tt!=0) ARes=ss* (x+y) + (tt-1+num)%num*W; at             Else  -Res= (ss-1) * (x+y) + (tt-1+num)%num*w;// -         } -cout<<res<<Endl; -     } -     return 0; in}
View Code

Be stunned by the code of XXX .... A similar way of solving a problem, but with a completely different wording

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5 6 using namespacestd;7 8 intMain ()9 {Ten     intx,y,w,n,res=0, tmp,mul,ans=0;  One      while(cin>>x>>y>>w>>N) { Atmp=x/w+1;//x time the number of pop-up balls -         //cout<<tmp<< ""; -Mul= (n1)/tmp;//How many times x time the         //cout<<mul<< ""; -Ans= (x+y) *mul;//ans Initialization -         //cout<<ans<< ""; -n-=mul*tmp;//N Value Update +         //cout<<n<<endl; -n--; +          while(n--){ Aans+=W; at         } -cout<<ans<<Endl; -     } -     return 0; -}
View Code

Another way to imitate the web search

1#include <stdio.h>2#include <string.h>3#include <iostream>4#include <algorithm>5#include <vector>6#include <queue>7#include <stack>8#include <Set>9#include <map>Ten#include <string> One#include <math.h> A#include <stdlib.h> -#include <time.h> - using namespacestd; the intMain () - { -         intX,Y,W,N,ANS,I,TP; -      while(~SCANF ("%d%d%d%d",&x,&y,&w,&N)) +     { -I=1; +ans=tp=0; A          while(i<N) at         { -             if(ans+w<tp+x) -             { -ans+=W; -i++; -             } in             Else if(ans+w==tp+x) -             { toi++; +tp+=x; -ans=TP; the                 if(i==n) Break; *i++; $tp+=y;Panax Notoginsengans=TP; -             } the             Else if(ans+w>tp+x) +             { Ai++; thetp=tp+x+y; +ans=TP; -             } $         } $printf"%d\n", ans); -     } -     return 0; the}
View Code

The first time to knock the simulation, almost crying, fortunately, I AC

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5 6 using namespacestd;7 8 intMain ()9 {Ten     intx,y,w,n,tmp,mul,ans=0;  One      while(cin>>x>>y>>w>>N) { A         intres=0; -             if(w>x) { -Res= (n1) * (x+y); the             } -             Else if(w==x) { -                  while(n!=0){ -n--; +                     //cout<< "n" <<n<<endl<<res<<endl; -                     if(n>1) +                     { Ares+=w+y; atn--;  -                     } -                     Else if(n==1) -                     { -res+=W; -n--; in}//cout<< "res" <<res<<endl; -                 } to             } +             Else { -                  while(n!=0) the                 { *n--; $                     intans=0;Panax Notoginseng                      while(ans+w<=x&&n!=0){ -ans+=W; then--; +                         //cout<< "ans" <<ans<<endl; A                     } the                     if(n!=0) +                     { -res+=x+y; $                     } $                     Elseres+=ans; -                     //cout<< "res" <<res; -                 } the             } -cout<<res<<Endl;Wuyi     } the     return 0; -}
View Code

hdu5417 Formula method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.