• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #224 Div2 B

 

Sponsored by
In English По-русски
HaibaraAi | Logout
 
 
 
 这题2500分居然是B题,脑子抽了?根本不能忍,总之,自己弄不出,看也不能根本解决问题啊0 0,先从b再到b暴力一次弄出循环节,再把剩余的m弄一下暴力,就差不多了!
 
  • Home
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Help

 
 
Codeforces Round #224 (Div. 2)
Finished
Practice
Add to favourites
 
 
→ Practice
 
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
 
 
→ Submit?
 
Language:
Choose file:
Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it will pass system tests.
 
 
→ Last submissions
 
SubmissionTimeVerdict
5936493 02/10/2014 11:00PM Accepted
5936360 02/10/2014 10:32PM Time limit exceeded on test 5
 
 
→ Problem tags
 
 
 
 
 
binary search
 
 
 
 
math
No tag edit access
 
 
→ Contest materials
 
  • Tutorial
     
  •  
     
     
  • Problems
  • Submit
  • My submissions
  • Status
  • Hacks
  • Room
  • Standings
  • Custom test
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.

Sample test(s)
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

Codeforces (c) Copyright 2010-2014 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: 02/10/2014 11:44PM (p1).
 
 
 
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff 
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1000025
14 #define pi acos(-1.0)
15 ll n, m, ans;
16 ll a, b, c, w, x, t, k, d, tmp;
17 int main(){
18     cin >> a >> b >> w >> x >> c;
19     m = max(0LL, c - a);
20     tmp = b;
21     while (tmp != b || d == 0){
22         k++;
23         if (b >= x){
24             b -= x;
25             d++;
26         }
27         else b = w - (x - b);
28     }
29     t = max(0LL, m / d - 1);
30     m -= t*d;
31     ans += t*k;
32     while (m > 0){
33         ans++;
34         if (b >= x){
35             b -= x;
36             m--;
37         }
38         else b = w - (x - b);
39     }
40     cout << ans;
41     return 0;
42 }
View Code
posted @ 2014-02-11 03:47  HaibaraAi  阅读(118)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3