#include<stdio.h>

//we have defined the necessary header files here for this problem.
//If additional header files are needed in your program, please import here. /* * 函数int deal(int n,int m):处理达到(n,m)转化为(1,1)时需要的次数
首先保证n<=m
当n==1时,deal(1,m)应该返回 m-1 (规律)
当n不为1且n==m时、或当n < 1时,无法转化到(1,1) 返回无效值-1
将deal(n,m)转化为deal(n,m%n),这里在n远远小于m时,远远比用减号要快,也不会Stackoverflow
如果deal(n,m%n)返回有效值,就把m/n这个转化次数加上返回
函数 resolve(n):对n进行从(1,n-1)(2,n-2)…(n/2,n-n/2)进行遍历调用
如果返回了合法值,就和min比较替换
返回时注意要加上首次拆开时的1次 */ int deal(int n,int m);
int resolve(int n); int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==){
printf("%d\n",);
}else{
printf("%d\n",resolve(n));
} }
return ;
} int deal(int n,int m){
int t = ;
if(n>m){
t=m;
m=n;
n=t;
} if(n==){
return m-;
} if((n==m && n!=) || n<){
return -;
} int changeTimes = m/n;
int d = deal(n,m%n);
if(d!=-){
return changeTimes+d;
} return -;
} int resolve(int n){
int min = ;
if(n<=){
return ;
} for (int i = ; i <= n/; i++)
{
int temp = -;
temp = deal(i,n-i);
if( (temp>=) && (temp<min) ){
min = temp;
}
}
return min+;
}
题目描述

Let's assume that we have a pair of numbers (a,b). We can get a new pair (a+b,b) or (a,a+b) from the given pair in a single step.

Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.

解答要求时间限制:1000ms, 内存限制:64MB
输入

The input contains the only integer n (1 ≤ n ≤ 106).Process to the end of file.

输出

Print the only integer k.

Pairs of Numbers的更多相关文章

  1. CF 403D Beautiful Pairs of Numbers

    The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following state ...

  2. Find Unique pair in an array with pairs of numbers 在具有数字对的数组中查找唯一对

    给定一个数组,其中每个元素出现两次,除了一对(两个元素).找到这个唯一对的元素. 输入:第一行输入包含一个表示测试用例数的整数T.然后T测试用例如下.每个测试用例由两行组成.每个测试用例的第一行包含整 ...

  3. 【题解】CF#403 D-Beautiful Pairs of Numbers

    这题还挺对胃口的哈哈~是喜欢的画风!回家路上一边听歌一边想到的解法,写出来记录一下…… 首先,由于 \(b_{k} < a_{k + 1}\) ,所以我们可以看作是在一个长度为 n 的序列上选择 ...

  4. [CF403D]Beautiful Pairs of Numbers

    题意:给定$n,k$,对于整数对序列$\left(a_1,b_1\right),\cdots,\left(a_k,b_k\right)$,如果$1\leq a_1\leq b_1\lt a_2\leq ...

  5. Codeforces 403D: Beautiful Pairs of Numbers(DP)

    题意:转换模型之后,就是1~n个数中选k个,放到一个容量为n的背包中,这个背包还特别神奇,相同的物品摆放的位置不同时,算不同的放法(想象背包空间就是一个长度为n的数组,然后容量为1的物体放一个格子,容 ...

  6. POJ 1320 Street Numbers 【佩尔方程】

    任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  7. Codeforces 395 D.Pair of Numbers

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. POJ 1320 Street Numbers 解佩尔方程

    传送门 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2529   Accepted: 140 ...

  9. Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Codeforces Round #586 (Div. 1 + Div. 2) E. Tourism

    链接: https://codeforces.com/contest/1220/problem/E 题意: Alex decided to go on a touristic trip over th ...

  2. 12、redis部分

  3. P2051 [AHOI2009]中国象棋 大力DP

    状压个啥$qwq$ 思路:大力$DP$ 提交:2次(自信的开了$int$) 题解:(见注释) #include<cstdio> #include<iostream> using ...

  4. KindEditor完全复制word内容

    我司需要做一个需求,就是使用富文本编辑器时,不要以上传附件的形式上传图片,而是以复制粘贴的形式上传图片. 在网上找了一下,有一个插件支持这个功能. WordPaster 安装方式如下: 直接使用Wor ...

  5. B/S架构大文件上传问题

    核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...

  6. 洛谷P4317 花神的数论题

    洛谷题目链接 数位$dp$ 我们对$n$进行二进制拆分,于是就阔以像十进制一样数位$dp$了,基本就是套模板.. 接下来是美滋滋的代码时间~~~ #include<iostream> #i ...

  7. 小米 oj 马走日 (bfs 或 双向bfs)

     马走日 序号:#56难度:困难时间限制:1500ms内存限制:10M 描述 在中国象棋中,马只能走日字型.现在给出一个由 N*M 个格子组成的中国象棋棋盘( 有(N+1)*(M+1)个交叉点可以落子 ...

  8. c/c++读取一行可以包含空格的字符串(getline,fgets用法)

    1.char[]型 char buf[1000005]; cin.getline(buf,sizeof(buf)); 多行文件输入的情况: while(cin.getline(buf,sizeof(b ...

  9. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

  10. MySQL字段命名不能使用的MySQL关键字

    #今天遇到一个问题,把某一字段重新命名为condition时报错,于是联想到可能是MySQL的关键字,用``引起来后,问题解决. #在MySQL数据库中,Table字段不能使用MySQL关键字: #[ ...