Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5417
Problem Descriptionvictor have a machine. When the machine is starts up, it'll pop out of a ball immediately. After then, the machine would pop out a ball everyWSeconds. However, the machine had some flaws, every time afterxSeconds of process the machine have to turn off foryseconds for maintenance. At the second of the machine would be shut down, it could pop out a ball. And while it's off, the machine would pop out no ball before the machine restart.
Now, at the 0 Second, the machine opens for the first time. Victor wants to know when the N--th ball would be a popped out. Could you tell him?
Inputthe input contains several test cases, at most -Cases.
Each line have four integersx,y,Wandn. Their meanings is shown above.
1≤x,y,w,n≤ .
Outputfor should output a line contains a number indicates the time when the n-th ball would be popped out.
Sample INPUT2 3 3 398 76 54 3210 9 8 100
Sample Output102664939 Test Instructions:
Victor has a machine that pops up a small ball every time the machine is opened, and then everyWW seconds will pop a small ball. Because the machine is not very perfect, every turn on the machinexx seconds to close y< Span class= "katex-html" >< Span class= "Mord mathit" >y seconds to adjust, in the moment the machine shuts down may have a small ball pop up, after the close until the next time the ball will not pop. 0 0 moment, Machine first opened, Victor wanted to know nn a small ball pops up the moment, can you tell him?"
Flood problem, simulation.
1#include <iostream>2 using namespacestd;3 4 intMain ()5 {6 intn,w,x,y;7 while(cin>>x>>y>>w>>N)8 {9 intt=0, tt=0;//TT records how long it takes to startTenn--; One while(n>0) A { -tt+=W; - if(tt<x) the { -n--; -t+=W; - } + Else if(tt==x) - { +n--; At+=W; at if(n>0) - { -tt=0; -t+=y; -n--; - } in } - Else to { +t+=w+x+y-tt; -tt=0; then--; * } $ }Panax Notoginsengcout <<t<<Endl; - } the return 0; + } A
View Code
HDU 5417 Victor and machine