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

2013 Asia Nanjing Regional Contest B

Poor Warehouse Keeper

Time Limit: 2000/1000 MS (Java/Others)    

Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 404    Accepted Submission(s): 117

Problem Description
Jenny is a warehouse keeper. He writes down the entry records everyday. The record is shown on a screen, as follow:
There are only two buttons on the screen. Pressing the button in the first line once increases the number on the first line by 1. The cost per unit remains untouched. For the screen above, after the button in the first line is pressed, the screen will be:
The exact total price is 7.5, but on the screen, only the integral part 7 is shown. Pressing the button in the second line once increases the number on the second line by 1. The number in the first line remains untouched. For the screen above, after the button in the second line is pressed, the screen will be:
Remember the exact total price is 8.5, but on the screen, only the integral part 8 is shown.
A new record will be like the following:
At that moment, the total price is exact 1.0. Jenny expects a final screen in form of:
Where x and y are previously given. What’s the minimal number of pressing of buttons Jenny needs to achieve his goal?
 
Input
There are several (about 50, 000) test cases, please process till EOF. Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 109) separated by a single space - the expected number shown on the screen in the end.
 
Output
For each test case, print the minimal number of pressing of the buttons, or “-1”(without quotes) if there’s no way to achieve his goal.
 
Sample Input
1 1
3 8
9 31
 
Sample Output
0
5
11
Hint
For the second test case, one way to achieve is: (1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)
 
Source
2013ACM/ICPC亚洲区南京站现场赛——题目重现
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4812 4810 4809 4808 4807 
 1 #include <cstdio>
 2 #include <vector>
 3 #include <cmath>
 4 #include <queue>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 using namespace std;
 9 #define INF 0x7fffffff
10 #define mod 1000003
11 #define ll long long
12 #define maxn 1005
13 #define pi acos(-1.0)
14 double n, m, k, x, y, a, b;
15 ll t,d;
16 int main(){
17     while (~scanf("%lf%lf", &x, &y)){
18         t = 0;
19         a = b = 1;
20         if (y<x){ printf("-1\n"); continue; }
21         y+=0.999;
22         while (a<=x&&b<=y-1){
23             if (b+1<=(y)*a/x){
24                 d = (ll) ((y)*a / x - b);
25                 t += d;
26                 b += d;
27             }
28             else{
29                 t++;
30                 b += (b / a);
31                 a++;
32             }
33         }
34         printf("%I64d\n", (ll)t);
35     }
36     return 0;
37 }
View Code
posted @ 2013-12-22 01:05  HaibaraAi  阅读(117)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3