hdu5417(BC)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5417
Victor and Machine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 87 Accepted Submission(s): 48
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 w seconds. However, the machine has some flaws, every time after x seconds of process the machine has to turn off for y 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 0 second, the machine opens for the first time. Victor wants to know when the n-th ball will be popped out. Could you tell him?
Now, at the 0 second, the machine opens for the first time. Victor wants to know when the n-th ball will be popped out. Could you tell him?
Input
The input contains several test cases, at most 100 cases.
Each line has four integers x, y, w and n. Their meanings are shown above。
1≤x,y,w,n≤100.
Each line has four integers x, y, w and n. Their meanings are shown above。
1≤x,y,w,n≤100.
Output
For each test case, you should output a line contains a number indicates the time when the n-th ball will be popped out.
Sample Input
2 3 3 3
98 76 54 32
10 9 8 100
Sample Output
10
2664
939
Source
题意:能看中文版,就不说题意了。
分析:机器每次运行关闭为一个回合,然后就是计算有多少个这样的回合了,注意特殊情况就OK了。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <stack> 5 #include <queue> 6 #include <map> 7 #include <set> 8 #include <vector> 9 #include <cmath> 10 #include <algorithm> 11 using namespace std; 12 #define ll long long 13 const double eps = 1e-6; 14 const double pi = acos(-1.0); 15 const int INF = 0x3f3f3f3f; 16 const int MOD = 1000000007; 17 18 int main () 19 { 20 int x,y,w,n; 21 while (scanf ("%d%d%d%d",&x,&y,&w,&n)==4) 22 { 23 int t; 24 if (x < w) 25 t = (x+y)*(n-1); 26 else 27 { 28 int a=x/w+1; 29 if (n%a==0) 30 t = (n/a)*(x+y)-y-x%w; 31 else 32 t = (n/a)*(x+y)+(n%a-1)*w; 33 } 34 printf ("%d\n",t); 35 } 36 return 0; 37 }