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

Victor有一个机器,这个机器每次开启的瞬间会弹出一个小球,之后每隔www秒会弹出一个小球。因为机器不是很完善,该机器每开启xxx秒就得关闭yyy秒进行调整,在机器关闭的瞬间可能会有小球弹出,关闭之后一直到下一次开启之前都不会有小球弹出。

000时刻,机器第一次开启,Victor想要知道第nnn个小球弹出的时刻,你能够告诉他吗?
输入描述
包含多组测试数据(最多一百组),每组测试数据一行。
输出描述
每组测试数据输出一行一个整数,即第nnn个小球弹出的时刻。
输入样例
2 3 3 3
98 76 54 32
10 9 8 100
输出样例
10
2664
939


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#include<cstdlib>
#define INF 0x3f3f3f3f

using namespace std;

int main()
{
	int n,x,y,w;
    while(~scanf("%d%d%d%d",&x,&y,&w,&n))
	{
		if(x<w)
		{
			printf("%d\n",(x+y)*(n-1));
		}
		else if(x==w)
		{
			if(n%2==0)
			printf("%d\n",(x+y)*(n/2-1)+x);
			else
			printf("%d\n",(x+y)*(n-1)/2);
		}
		else
		{
			int num=0;
			num=1+x/w;
			if(n%num==0)
			{
			   printf("%d\n",(n/num-1)*(x+y)+w*(num-1));
			}
			else
			{
				printf("%d\n",(n/num)*(x+y)+(n-n/num*num-1)*w);
			}
		}
	}

}


你可能感兴趣的:(BestCoder Round #52 (div.2) Victor and Machine)