Codeforces Perfect Pair (JAVA)
http://codeforces.com/problemset/problem/317/A
题意:给两个数字,可以两数相加去替换其中一个数字。问要做多少次,可以让两个数字钟至少一个 >= 目标数字m,输出次数,不可能的话输出-1
比较简单的题目,用来练习JAVA,代码写得有点,呵呵................
import java.util.*; public class Main{ static long max(long x , long y){
return x > y ? x : y;
} static long solve(long a ,long b ,long c){
long res = 0;
while( (a >= c || b >= c) == false){
long sum = a + b;
long Max = max(a , b);
a = sum; b = Max;
res++;
}
return res;
}
static long __solve(long a , long b , long c){
long res = (-b + a - 1) / a;
long tmp = b + res * a;
res += solve(a,tmp,c);
return res;
} public static void main(String[] args){
Scanner cin = new Scanner(System.in);
long a,b,c,res;
a = cin.nextLong();
b = cin.nextLong();
c = cin.nextLong();
if(a >= c || b >= c)
res = 0;
else if(a <= 0 && b <= 0)
res = -1;
else if(a >= 0 && b >= 0){
res = solve(a,b,c);
}
else{
long tmp;
if(a < b){
tmp = a; a = b; b = tmp;
}
res = __solve(a,b,c);
} System.out.println(res);
}
}
Codeforces Perfect Pair (JAVA)的更多相关文章
- [codeforces 317]A. Perfect Pair
[codeforces 317]A. Perfect Pair 试题描述 Let us call a pair of integer numbers m-perfect, if at least on ...
- 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 ...
- Continued Fractions CodeForces - 305B (java+高精 / 数学)
A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...
- [CodeForces 892A] Greed (Java中sort实现从大到小排序)
题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...
- cf Perfect Pair
http://codeforces.com/contest/318/problem/C #include <cstdio> #include <cstring> #includ ...
- CodeForces 359D Pair of Numbers (暴力)
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...
- [codeforces] 359D Pair of Numbers
原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...
- Codeforces 359D Pair of Numbers | 二分+ST表+gcd
题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...
- 深入理解Java之泛型
原文出处: absfree 1. Why ——引入泛型机制的原因 假如我们想要实现一个String数组,并且要求它可以动态改变大小,这时我们都会想到用ArrayList来聚合String对象.然而,过 ...
随机推荐
- centos安装firefox flash插件
centos下的firefox flash插件默认不是最新版的,安装过程如下: 将安装地址添加到repolist中 sudo yum -y install http://linuxdownload.a ...
- paip.日期时间操作以及时间戳uapi php java python 总结
paip.日期时间操作以及时间戳uapi php java python 总结 ///uapi Date 函数 | Day 函数 | Hour 函数 | Minute 函数 | Month 函数 | ...
- R 报错:package ‘***’ is not available (for R version ****) 的解决方案
R 安装sparklyr,ggplot2等包出现如下warning package '****' is not available (for R version 3.0.2) 系统环境 ubuntu1 ...
- seajs加载jquery时提示$ is not a function该怎么解决
这篇文章主要介绍了seajs加载jquery时提示$ is not a function该怎么解决的相关资料,需要的朋友可以参考下 jquery1.7以上的都支持模块化加载,只是jquery默认的是支 ...
- 使用Reveal查看任意App的技巧
转:http://www.jianshu.com/p/4dc8f94ca27c 前言 Reveal(http://revealapp.com)是一个很强大的iOS View Hierarchy工具,与 ...
- SQL SERVER 2008中输入汉字乱码的问题
搭建服务器时,系统是英文版windows server 2008 ,安装的中文语言包.安装SqlServer2008 后,数据库中文显示乱码. baidu 后,说是 排序规则 的问题.修改为 Chin ...
- 【Android开发坑系列】如何让Service尽可能存活
流行的思路如下[2015-11-20更新]: 1.让Service杀不死.Service的onStartCommand返回START_STICKY,同时onDestroy里面调用startServic ...
- Word中怎么设置标题的自动编号
转自: http://jingyan.baidu.com/article/4f7d5712c39c0a1a201927ea.html
- jsp中表格,表格中的文字根据表格的大小自动换行
style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word" 语法: word-break : ...
- cocos2d-x 3.0rc2中读取sqlite文件
cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败.须要复制到可写的路径下 sqlite3* dbFile = NULL; std::string ...