B. Number Busters----数学推演

B. Number Busters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Arthur and Alexander are number busters. Today they've got a competition.

Arthur took a group of four integers a, b, w, x (0 ≤ b < w, 0 < x < w) and Alexander took integer с. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: c = c - 1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if b ≥ x, perform the assignment b = b - x, if b < x, then perform two consecutive assignments a = a - 1; b = w - (x - b).

You've got numbers a, b, w, x, c. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if c ≤ a.

Input

The first line contains integers a, b, w, x, c (1 ≤ a ≤ 2·109, 1 ≤ w ≤ 1000, 0 ≤ b < w, 0 < x < w, 1 ≤ c ≤ 2·109).

Output

Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.

Examples
input
4 2 3 1 6
output
2
input
4 2 3 1 7
output
4
input
1 2 3 2 6
output
13
input
1 1 2 1 1
output
0

题目链接:http://codeforces.com/contest/382/problem/B


这个题的意思是说给你5个数a,b,w,x,c;

我们有两种操作,一种是当b>=x时,b-=x;

另一种是当b<x时,b=w-(x-b);


我的方法是算一下循环次数,然后直接看最后一次,然后华丽丽的超时了,看了大神们的思路,我只感觉我还是个孩子,为什么要这样伤害我。

我们首先会发现只有当b<x时c和a的差距才会拉近,我们简单的处理一下

c=c-a;

w=w-x;

这里很容易就能知道原因是什么

然后我们会发现,第一种情况很明显发生了c次(计算之后的c)

然后我们假设第二种情况发生了k次,我们在推理的过程中会发现b永远是>=0的,所以b-c*x+k*w>=0

所以k>=((c*x)-b)/w;

然后向上取整就可以了。

借鉴大神们的思路

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define LL long long
using namespace std;
int main(){
    LL a,b,w,x,c;
    cin>>a>>b>>w>>x>>c;
    c-=a;
    w-=x;
    if(c<=0)
        return 0*printf("0\n");
    else{
        LL k=ceil((1.0*(x*c-b))/w);
        cout<<c+k<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值