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/ ...
随机推荐
- 错误记录:html隐藏域的值存字符串时出错
问题 webform在后台给前台传值. <input type="hidden" value="<%=userType %>" id=&qu ...
- [转]Linux之type命令
转自:http://codingstandards.iteye.com/blog/831504 用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keywo ...
- C语言实现strcmp
注意转化为unsigned char: strcmp.h #ifndef STRCMP_H #define STRCMP_H /************************************ ...
- Python编程中的反模式
Python是时下最热门的编程语言之一了.简洁而富有表达力的语法,两三行代码往往就能解决十来行C代码才能解决的问题:丰富的标准库和第三方库,大大节约了开发时间,使它成为那些对性能没有严苛要求的开发任务 ...
- Window Redis分布式部署方案 java
Redis分布式部署方案 Window 1. 基本介绍 首先redis官方是没有提供window下的版本, 是window配合发布的.因现阶段项目需求,所以研究部署的是window版本的,其实都 ...
- echart图表控件配置入门(一)
现在主流的web图表控件主要有hightchart.fusionchart.echart: echart作为百度前端部门近期推出的一个基于html5的免费图表控件,以其丰富图表类型和良好的兼容性速度得 ...
- 14个超赞的响应式HTML5模板免费下载
现在HTML5已经势不可挡.很多朋友开始学习HTML5,当你已经学习过一些HTML5的教程之后,是不是想立即开始实战了呢?对,现在就开始吧,不过 找一些优秀的HTML5模板案例练习是相当不错的注意.当 ...
- dom 按着shift多选
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 利用AuthorizeAttribute属性简单避免 MVC 中的跨域攻击
跨域攻击---自然来路页面和目标页面不在同一个域下,所以直接判断来路域和当前自己的域就可以了. 可以广泛应用于表单提交,ajax调用或者某些不想让用户直接输入网址看到的页面 [csharp] view ...
- LoadRunner执行自动化以及报告自动化的方法
There are three major articles KB articles on Automating LR: 1. Command line arguments for the LoadR ...