#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. 题解 [BZOJ4144] Petrol

    题目描述 ​ 有一张 n 个点 m 条边的无向图,其中有 s 个点上有加油站.有 Q 次询问(a,b,c), 问能否开一辆油箱容积为 c 的车从 a 走到 b.(a,b均为加油站) 输入格式 ​ 第一 ...

  2. centos6.5linux安装docker之升级内核

    一.运行docker Linux内核版本需要在3.8以上,针对centos6.5 内核为2.6的系统需要先升级内核.不然会特别卡 在yum的ELRepo源中,有mainline(4.5).long-t ...

  3. @Test 测试

    package com.自定义.mall.admin.system; import java.util.List; import java.util.Map; import javax.annotat ...

  4. 【luoguP3959 宝藏】-状压DP

    题目描述: 参与考古挖掘的小明得到了一份藏宝图,藏宝图上标出了 n 个深埋在地下的宝藏屋, 也给出了这 n 个宝藏屋之间可供开发的m 条道路和它们的长度. 小明决心亲自前往挖掘所有宝藏屋中的宝藏.但是 ...

  5. 位运算(C++)

    C++输出十六进制 #include<iostream> #include<iomanip> using namespace std; int main() { ; ; int ...

  6. 数据结构实验之链表二:逆序建立链表(SDUT 2117)

    题目链接 #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; ...

  7. Spring Cloud Eureka(四):Eureka 配置参数说明

    Eureka Client 配置项(eureka.client.*) org.springframework.cloud.netflix.eureka.EurekaClientConfigBean 参 ...

  8. 使用create-react-app创建项目(一)——端口配置

    在package.json文件中找到 "scripts",在start中添加"set PORT=8000" "scripts": { &qu ...

  9. GDB之调试器用法

    GDB 完成的作用: 启动程序,可以按照工程师自定义的要求随心所欲的运行程序 让被调试的程序在工程师指定的断点处停住,断点可以是条件表达式 当程序被停住时,可以检查此时程序中所发生的事,并追索上文 动 ...

  10. LeetCode 84. 柱状图中最大的矩形(Largest Rectangle in Histogram)

    题目描述 给定 n 个非负整数,用来表示柱状图中各个柱子的高度.每个柱子彼此相邻,且宽度为 1 . 求在该柱状图中,能够勾勒出来的矩形的最大面积. 以上是柱状图的示例,其中每个柱子的宽度为 1,给定的 ...