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

当时应该仔细分析一下这个题目的。

只有b>=x的时候这个时候c才开始追a。

而当b<x的时候c与a的差并不会发生变化。

所以当c与a追平的时候一定是在上面的轮回。

于是我们可以有式子:

b - x*(c-a) + (w-x)*k >= x - x;

也就是最极端的情况就是b刚好变成0的时候c追上a。

然后可以解k的不等式,这时候k要取整数,所以应该是向上取整。

最后加上一个c-a就ok了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include <map>
using namespace std;
const int MAXN = 2333;
const int inf = 1e9;
long long a,b,w,x,c;
int main()
{scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&w,&x,&c);double k = (x*(c-a) - b)*1.0/(w-x);long long x = ceil(k);long long ans = c - a + (x>0?x:0);printf("%I64d\n",ans);return 0;
}

B. Number Busters相关推荐

  1. CF contest/382/B. Number Busters

    题解:    设t 分钟后:     c'=c-t;    a'=a- (x*t-b)/w;     c'<=a';     整理出来 t>= (a*w-cw+b)/(x-w);    注 ...

  2. Fraud Busters

    Fraud Busters 链接:https://ac.nowcoder.com/acm/contest/7852/H 来源:牛客网 The number of cars in Default Cit ...

  3. UVa 109 - SCUD Busters(凸包计算)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  4. input属性为number,maxlength不起作用的解决方案

    <input type="text" maxlength="11" /> 效果ok, 当 <input type="number&q ...

  5. ORA-19502: write error on file xxxxx, block number xxxx

    错误现象: 在ORACLE 10g下为表空间IGNITE_EGVSQL01增加数据文件时,报如下错误: SQL> ALTER TABLESPACE IGNITE_EGVSQL01      AD ...

  6. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

  7. HDU 1711 Number Sequence(KMP算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/ ...

  8. LeetCode 191 Number of 1 Bits

    LeetCode 191 Number of 1 Bits 解法一(较为传统都解法):使用将n不断右移,并与1想&得到1的个数:(也有使用除法/2的,明显除法的运行效率要低于位移) 时间复杂度 ...

  9. [BuildRelease]build number / id

    build number, 也称为build id, 在build release的流程中唯一标示一个build,也是正式的产品的product version 和file version后两位(Ma ...

最新文章

  1. 关于更改linux源文件的问题(ubuntu)
  2. 校园网断线重连,用爬虫来搞定!
  3. java中 queryparam_@PathParam 和 @QueryParam
  4. Jsoup获取所有链接
  5. mysql解压版安装配置
  6. 数据结构思维 翻译完成
  7. 查询数据库中所有表名称
  8. SaaS产品服务进行网络推广的必要性
  9. linux内核奇遇记之md源代码解读之五
  10. Atitit mysql存储过程编写指南 1. 定义变量 1 1.1. 变量名以@开头用户变量 会话变量 1 1.2. 以declare关键字声明 存储过程变量 2 1.3. @是用户自定义变量,
  11. Numpy中高维axis的操作个人理解
  12. 有中国驾照的情况下,在美国怎么考驾照?
  13. 【2022第十届‘泰迪杯’挑战赛】A题:害虫识别完整版(大致思路。详细过程和代码以及结果csv在压缩包中)
  14. IOS App的简单开发实例
  15. 从程序员到产品经理再到自己创业的心路历程
  16. Android仿斗鱼滑动登录验证
  17. 【Shiro】6、Shiro实现限制密码错误次数从而限制用户登录
  18. zynq 7000 clg400 可作为外部AD 的引脚列表
  19. 广州番禺翠湖山庄小区规划图
  20. 2009年9月25日微软发布VB6-SP6b

热门文章

  1. “任务管理器”中“进程”各个选项卡的含义?
  2. 微信公众账号开发模式1
  3. 世界的本质是旋转(1)复平面与欧拉公式
  4. 进程(线程)间同步互斥问题(四) 三个烟鬼问题
  5. tmpfs - 临时文件系统
  6. 乐信,转向路口的横风
  7. MySQL之多表查询
  8. 将英文版的sharepoint网站模板转成中文Sharepoint可以使用的模板
  9. ShardingJDBC分表说明
  10. VS2019 C++的跨平台开发——C# WPF