Victor and Machine----(BestCoder Round #52 (div.2))

来源:互联网 发布:阿里云战略合作伙伴 编辑:程序博客网 时间:2024/05/12 18:06

Victor and Machine

 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 131072/65536 K (Java/Others)
Problem Description

Victor has a machine. When the machine starts up, it will pop out a ball immediately. After that, the machine will pop out a ball every ww seconds. However, the machine has some flaws, every time after xx seconds of process the machine has to turn off for yy seconds for maintenance work. At the second the machine will be shut down, it may pop out a ball. And while it's off, the machine will pop out no ball before the machine restart.

Now, at the 00 second, the machine opens for the first time. Victor wants to know when the nn-th ball will be popped out. Could you tell him?

Input

The input contains several test cases, at most 100100 cases.

Each line has four integers xxyyww and nn. Their meanings are shown above。

1\leq x,y,w,n\leq 1001x,y,w,n100.

Output

For each test case, you should output a line contains a number indicates the time when the nn-th ball will be popped out.

Sample Input
2 3 3 398 76 54 3210 9 8 100
Sample Output
102664939

分析:直接模拟就行,最好把第一次开启时排除,然后捆绑先关闭和后开启。这样算起来方便些。

很遗憾,这次没在状态,只完成了一题。掉分了,还有codeforces也掉了,呜呜··

CODE:

#include <iostream>using namespace std;int main(){    long long x,y,w,n;    while(cin>>x>>y>>w>>n){        long long t=x/w+1;        long long tim;        if(n%t==0){            tim=(n/t-1)*(x+y)+(t-1)*w;        }        else{            tim=(n/t)*(x+y)+(n%t-1)*w;        }        cout<<tim<<endl;    }    return 0;}




0 0
原创粉丝点击