Codeforces Round #188 (Div. 2) C. Perfect Pair 数学
B. Strings of Power
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/318/problem/C
Description
Two integers x, y are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (x + y).
What is the minimum number of such operations one has to perform in order to make the given pair of integers m-perfect?
Input
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.
Output
Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the m-perfect one.
Sample Input
1 2 5
Sample Output
2
HINT
题意
给你x,y,每次你可以选择一个数,让他变成x+y,然后问最少多少步,可以使得x,y中的最大值大于等于k
题解:
这道题类似于fib数,所以我们只要把(x,y)变成(y,x+y)就好
注意,全程爆ll
代码:
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- #include <stack>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define test freopen("test.txt","r",stdin)
- #define maxn 4000001
- #define mod 10007
- #define eps 1e-9
- const int inf=0x3f3f3f3f;
- const ll infll = 0x3f3f3f3f3f3f3f3fLL;
- inline ll read()
- {
- ll x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- //**************************************************************************************
- int main()
- {
- ll x=read(),y=read(),k=read();
- if(x>=k||y>=k)
- {
- cout<<""<<endl;
- return ;
- }
- if(x<k&&y<k&&x<=&&y<=)
- {
- cout<<"-1"<<endl;
- return ;
- }
- ll ans=;
- if(x>y)
- swap(x,y);
- if(x<)
- {
- ans=(y-x)/y;
- x+=ans*y;
- }
- while(y<k)
- {
- ll tmp=x;
- x=y;
- y=tmp+y;
- ans++;
- }
- cout<<ans<<endl;
- }
Codeforces Round #188 (Div. 2) C. Perfect Pair 数学的更多相关文章
- Codeforces Round #188 (Div. 1 + Div. 2)
A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...
- Codeforces Round #460 (Div. 2) B Perfect Number(二分+数位dp)
题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
- Codeforces Round #188 (Div. 2) B. Strings of Power 水题
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #188 (Div. 2) A. Even Odds 水题
A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces Round #460 (Div. 2)-B. Perfect Number
B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...
- 【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers
将整个游戏可以划分成若干个互不相交的子游戏. 每个子游戏的sg值只与其中的数的个数有关.而这个数不会超过30. 于是可以预处理出这个sg值表. 然后从1到n枚举,对<=sqrt(n)的部分,用个 ...
- Codeforces Round #274 (Div. 1) B. Long Jumps 数学
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...
随机推荐
- Oracle中本行记录和上一行记录进行比较lead over 函数处理
遇到问题:多表关联查询,有一个要求是,同一保单号,对应多个投资产品Code.以及投资比例,每一个保单号有一个总的投资金额.要求同一保单号那一行,只有第一个总金额有值,剩下的code对应的总金额置空. ...
- [python]Python操作MySQL
[安装] 安装MySQL 安装MySQL不用多说了,下载下来安装就是,没有特别需要注意的地方. 一个下载地址:点击打开链接 [样例] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- @Html.Raw()
asp.net mvc中把html字符串以html效果输出来, @string变更输出的是HTML代码, 如果想以HTML标签效果输出来可以用函数@Html.Raw(str) 输出来的就是网效果了, ...
- Windows8.1 安装office2013并激活
之前笔记本上安装的东西太多了,启动比较慢,打算重做系统,正好同事有一个Windows8.1的系统盘,直接做了一个Windows8.1的系统.界面清爽,速度还可以,系统安装完成以后,准备安装office ...
- Redhat=》中文
我的redhat安装时没有提示语言选项,由于工程需要,支持汉字是不可避免的,因此就必须安装中文输入法. 安装中文包 将系统光盘镜像文件连接至计算机,我的镜像是RHEL5.1的,先将光盘挂载至/mnt目 ...
- HTML5每日一练之OL列表的改良
在HTML5中的OL被改良了,为它增加了两个新属性. start属性:start属性用来定义列表编号的起始位置,比如下面的代码,列表将从50开始51...55以此类推 <ol start=&qu ...
- HDU 1002 分类: ACM 2015-06-18 23:03 9人阅读 评论(0) 收藏
昨天做的那题其实和大整数相加类似.记得当初我大一寒假就卡在这1002题上,结果之后就再也没写题... 到今天终于把大整数相加写了一遍. 不过写的很繁琐,抽时间改进一下写简洁一点. #include&l ...
- Linux下安装protobuf并实现简单的客户端服务器端通信
http://code.google.com/p/protobuf/downloads/list上可以下载Protobuf的源代码. 安装步骤如下所示: 1>tar -xzf protobuf- ...
- HDU 5777 domino (排序,水题)
题意:小白在玩一个游戏.桌子上有n张多米诺骨牌排成一列.它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒.每个骨 牌倒下的时候,若碰到了未倒下的 骨牌,可以把它推倒.小白现在可以随意设置骨 ...
- Android Studio使用JNI
0x01 前言 本文讲述使用Android Studio通过静态注册.动态注册使用JNI的方法,以及加载第三方so文件的方法 0x02 Android Studio静态注册的方式使用JNI 1. 添加 ...