#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. [2019牛客多校第二场][E. MAZE]

    题目链接:https://ac.nowcoder.com/acm/contest/882/E 题目大意:有一个\(n\times m\)的01矩阵,一开始可以从第一行的一个点出发,每次可以向左.向右. ...

  2. @WebFilter 的使用及采坑

    @WebFilter@WebFilter 用于将一个类声明为过滤器,该注解将会在部署时被容器处理,容器将根据具体的属性配置将相应的类部署为过滤器.该注解具有下表给出的一些常用属性 ( 以下所有属性均为 ...

  3. 【leetcode】1295. Find Numbers with Even Number of Digits

    题目如下: Given an array nums of integers, return how many of them contain an even number of digits. Exa ...

  4. springboot中使用spring security,登录url就出现403错误

    参考链接:https://segmentfault.com/q/1010000012743613 有两个controller,一个是所有用户可以访问的@RequestMapping("use ...

  5. 「BZOJ 4565」「HAOI 2016」字符合并「区间状压DP」

    题意 给一个长度为\(n(\leq 300)\)的\(01\)串,每次可以把\(k(\leq 8)\)个相邻字符合并,得到新字符和一定分数,最大化最后的得分 题解 考虑设计dp:\(dp[S][i][ ...

  6. Java核心复习 —— ArrayList源码阅读

    一.ArrayList 介绍 ArrayList是List接口可变数组的实现. 特点 非线程安全 查找和修改效率高 二.ArrayList 使用方法 remove元素 @Test public voi ...

  7. docker-compose部署微服务

    1.安装docker-compose curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose ...

  8. Qt 单元测试

      使用Qtcreator 自带的单元测试工具框架QTestlib进行测试. 一.创建一个单元测试程序 new project->other project ->Qt unit test ...

  9. 数据结构之链表(Linked list)

    1, 无序链表(Unordered linked list) 链表是有若干个数据节点依次链接成的数据结构,如下图所示,每一个数据节点包括包括数据和一个指向下一节点的指针.(python中的list就是 ...

  10. [Java]用 MessageFormat 拼接组合字符串

    package com.hy; import java.text.MessageFormat; public class Test3 { public static void main(String[ ...