2013ACM/ICPC亚洲区南京站现场赛---Poor Warehou…
2018-06-27 09:58:51来源:未知 阅读 ()
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=4803
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?
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.
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <set> #include <queue> #include <vector> using namespace std; const double esp=1e-8; int main() { double x,y,s1,s2; while(scanf("%lf%lf",&x,&y)!=EOF) { y+=0.9999999; long long sum=0; if(x>y) { puts("-1"); continue; } s1=1.0; s2=1.0; while(1) { if(s1-x+esp>=esp&&s1-(x+1)<esp) break; long long t=(long long)(y*s1/x-s2); sum+=t; s2=s2+t; s2=s2*(s1+1)/s1; s1=s1+1; sum++; if(s1>=x&&s1-(x+1)<esp) break; } sum+=(long long)(y-s2); printf("%lld\n",sum); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 2019 ICPC 银川站 2019-12-11
- 统计字符的个数,能够组成几个acmicpc 2019-10-16
- 2017 ICPC网络赛(西安)--- Xor 2019-05-04
- Duizi and Shunzi HDU - 6188 (贪心)2017 广西ACM/ICPC 2018-09-10
- 2017 ICPC区域赛(西安站)--- J题 LOL(DP) 2018-06-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash