BestCoder Round #52 (div.2) 1001题

来源:互联网 发布:基于单片机音乐播放器 编辑:程序博客网 时间:2024/06/05 10:56

Victor and Machine

Accepts: 452
Submissions: 1123
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 everywww seconds. However, the machine has some flaws, every time after xxx seconds of process the machine has to turn off for yyy 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 000 second, the machine opens for the first time. Victor wants to know when the nnn-th ball will be popped out. Could you tell him?

Input

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

Each line has four integers xxx,yyy,www and nnn. Their meanings are shown above。

1≤x,y,w,n≤1001\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 thennn-th ball will be popped out.

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

分析:理解题意的时候总是想不明白,想了好久才明白,因为每次重新开始都会弹出一个球,而且每次修理后都会重新开始,理解这些就好了,然后直接模拟就好,1A

代码:

#include <cstdio>#include <cstring>#include <algorithm>#include<iostream>using namespace std;#define LL long longint main(){    int x,y,w,n,a,b;    while(cin>>x>>y>>w>>n){         a=x/w; //在要停下修理之前可以弹出的小球个数        b=x%w;        int sum=0,t=0;        n--;        int i;       for( i=n;i>0;i--){ //每次开始--,表示弹一个球            if(i-a<=0){                sum+=i*w;//有可能不用弹a个就达到n个要求了            break;            }            else{            i-=a;            sum+=a*w+y+b;//时间和加上从开始一直到再一次的开始            }       }        cout<<sum<<endl;    }    return 0;}




0 0
原创粉丝点击