[原创]codeforces 382B B. Number Busters [二分答案+数学]【思维】
[原创]codeforces 382B B. Number Busters [二分答案+数学]【思维】
2017-01-22 13:52:08 Tabris_ 阅读数:308
博客爬取于2020-06-14 22:42:00
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/54668103
题目链接:http://codeforces.com/contest/382/problem/B
----------------------------------------------------------------------------------------------------.
B. Number Busters
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
----------------------------------------------------------------------------------------------------.
题目大意:
就是两个人,一个人有4个数字,另一个人有1个数字,每一秒第二个人的数字减一c--
,每一秒第一个人的数字变化如下,if(b>=x) b=b-x;else a--,b=w-(x-b);
现在问你最少多长时间之后a<=c?
解题思路:
很明显的二分答案,但是对于check
部分还是要推敲一下,
首先if(b>=x) b=b-x;else a--,b=w-(x-b);
可以改变成 if(b>=x) b=b-x;else a--,b=b-x+w;
显然就是 在b<0的时候将+w,与此同时a–,
那么在c减少n的时候a减少的数m就满足 b=b-nx+mw&&b>0,(m取最小值);
与此同时注意a,c可能小于0,所以二分答案的边界要大一点.
附本题代码
----------------------------------------------------------------------------------------------------.
1 | # include <bits/stdc++.h> |