[codeforces 317]A. Perfect Pair

试题描述

Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.

Two integers xy 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?

输入

Single line of the input contains three integers xy and m ( - 1018 ≤ xym ≤ 1018).

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 %I64dspecifier.

输出

Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the m-perfect one.

输入示例

-  

输出示例


数据规模及约定

见“输入

题解

如果都是整数,那么不难发现增长率和斐波那契数列相同,就是指数级的,所以直接模拟即可。注意特判有负数的情况。如果只有一个负数,先把这个负数加成正的再模拟。如果两个都是负数,那么不可能再变大了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;
#define LL long long const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
LL read() {
LL x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} LL x, y, m; int main() {
x = read(); y = read(); m = read(); if(x > y) swap(x, y);
if(x <= 0 && y <= 0 && y < m) return puts("-1"), 0;
if(y >= m) return puts("0"), 0;
LL cnt = abs(x) % y ? abs(x) / y + 1 : abs(x) / y;
x += cnt * y; if(x > y) swap(x, y);
while(y < m) {
x = x + y;
if(x > y) swap(x, y);
cnt++;
} printf("%I64d\n", cnt); return 0;
}

[codeforces 317]A. Perfect Pair的更多相关文章

  1. Codeforces 980 D. Perfect Groups

    \(>Codeforces\space980 D. Perfect Groups<\) 题目大意 : 设 \(F(S)\) 表示在集合\(S\)中把元素划分成若干组,使得每组内元素两两相乘 ...

  2. Codeforces Perfect Pair (JAVA)

    http://codeforces.com/problemset/problem/317/A 题意:给两个数字,可以两数相加去替换其中一个数字.问要做多少次,可以让两个数字钟至少一个 >= 目标 ...

  3. 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/p ...

  4. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  5. Codeforces 934 A.Compatible Pair

    http://codeforces.com/contest/934 A. A Compatible Pair   time limit per test 1 second memory limit p ...

  6. cf Perfect Pair

    http://codeforces.com/contest/318/problem/C #include <cstdio> #include <cstring> #includ ...

  7. Codeforces 923 C. Perfect Security

    http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...

  8. Codeforces 919 B. Perfect Number

      B. Perfect Number   time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces #317 C.Lengthening Sticks(数学)

    C. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. DRY原则

    DRY--Don't Repeat Yourself Principle,直译为"不要重复自己"原则 DRY简而言之,就是不要写重复的代码.原则本身很简单,但是,对于OOAD(面向 ...

  2. php装饰器模式完成文章编辑

    <?php //文章父类 class BaseArt{ protected $content; protected $art; public function __construct($cont ...

  3. 【浅谈html5 响应式布局之自动适应屏幕宽度】

    允许网页宽度自动调整 “自适应网页设计”到底是怎么做到的?其实并不难. 首先,在网页代码的头部,加入一行viewport元标签. <meta name=”viewport” content=”w ...

  4. Struts2 中Parameters是如何获取值的

    刚刚学习struts2的知识,在练习struts2的默认语言OGNL过程中,对于<p>parameters:<s:property value="#parameters.u ...

  5. sqlmap写文件为空之谜

    恰逢有一个SQL注入可以通过sqlmap进行,而且权限高得离谱,直接就是root权限.既然是root权限当然是想直接getshell咯.可是只是sqlmap -u xxx --os-shell的时候却 ...

  6. MVC下的客户端模板技术

    1.引言 在Web编程中,我们有时经常需要使用Ajax来访问服务端的接口,然后使用这些返回的数据(一般格式都是JSON)来展示客户端的相关信息.例如:在一个商品列表,我们点击某一样的商品,查看该商品的 ...

  7. [Ljava.lang.String和java.lang.String区别

    在做项目时报了一个got class [Ljava.lang.String的提示,当时看到[Ljava.lang.String这个时,感觉有点怪怪的,第一次遇到这种情况.最后在网上查了下才明白.是数组 ...

  8. 2015年12月13日 spring初级知识讲解(四)面向切面的Spring

    2015年12月13日 具体内容待补充...

  9. 存储过程获取最后插入到数据表里面的ID

    存储过程获取最后插入到数据表里面的ID SET NOCOUNT on;---不返回影响行数提高性能GOcreate proc [sp_bbs_thread_Insert] @id int output ...

  10. Unity3D 学习笔记

    不是什么技术文章,纯粹是我个人学习是遇到一些觉得需要注意的要点,当成笔记. 1.关于调试,在Android下无法断点,Debug也无法查看,查看日志方法可以启动adb的log功能,或者自己写个GUI控 ...