CF382B Number Busters

· · 题解

分析

有以下两种操作。

那么我们就跟着上面的操作进行模拟即可。一直循环,判断 b 和 x 的关系,然后完成对应操作,记得每一次答案(秒数)+1。

代码

#include<iostream>
long long a,b,w,x,c;
int main(){
    std::cin>>a>>b>>w>>x>>c;
    int res=0;
    while(c>a){
        if(b>=x){
            b-=x,c--;
        }else{
            a--,c--;
            b=w-(x-b);
        }
        res++;
    }
    std::cout<<res;
}