题目链接:

C. Memory and De-Evolution

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.

In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.

What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?

Input

The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

Output

Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.

Examples
input
6 3

output
4

input
8 5

output
3

input
22 4

output
6

题意:

把变成为x的等边三角形变成边长为y的三角形,其中过程要求三角形恒成立,最少需要操作多少次;

思路:

反过来贪心;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>using namespace std;#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));typedef  long long LL;template<class T> void read(T&num) {char CH; bool F=false;for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {if(!p) { puts("0"); return; }while(p) stk[++ tp] = p%10, p/=10;while(tp) putchar(stk[tp--] + '0');putchar('\n');
}const int mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=(1<<20)+10;
const int maxn=1e5+110;
const double eps=1e-12;int x,y;
queue<int>qu;
int main()
{read(x);read(y);int ans=0;qu.push(y);qu.push(y);qu.push(y);while(1){int f=qu.front();qu.pop();int g=qu.front();qu.pop();int u=qu.front();qu.pop();if(f>=x&&g>=x&&u>=x)break;ans++;qu.push(g);qu.push(u);qu.push(g+u-1);}cout<<ans<<endl;return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5876913.html

codeforces 712C C. Memory and De-Evolution(贪心)相关推荐

  1. codeforces#324(div2) E. Anton and Ira 贪心

    codeforces#324(div2) E. Anton and Ira  贪心 E. Anton and Ira time limit per test 1 second memory limit ...

  2. Codeforces 712C. Memory and De-Evolution

    题目链接:http://codeforces.com/problemset/problem/712/C 题意: 给你两个值 a 和 b (a > b), 代表这里有两个等边三角形, 边长分别为 ...

  3. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  4. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

  5. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  6. 【Codeforces】925A Stairs and Elevators【贪心】

    [Codeforces]925A Stairs and Elevators [题目大意] 在一个n*m的矩阵里,有clcl个楼梯和cece个电梯,电梯和楼梯可以到任意一层,给出clcl个楼梯的位置和c ...

  7. Codeforces 814D An overnight dance in discotheque 贪心

    题意 题解 Codeforces 814D An overnight dance in discotheque 物语场!!!!之后的可怜和命运石之门--哈哈哈哈哈哈哈-- 题意 平面直角坐标系中有n个 ...

  8. Codeforces Round #579 (Div. 3) E. Boxers (贪心)

    题目链接:https://codeforces.com/contest/1203/problem/E 思路:一开始想的是记录数字出现次数,看每个数字的三种变化能否产生新数,但是这样容易多算或者少算答案 ...

  9. codeforces 584 E. Anton and Ira(贪心,数组p经变换到数组s)

    题目:http://codeforces.com/contest/584/problem/E 题意:有两个数组p,s,长度为n,且是1~n的排列.要使数组p变为s,每交换 i 和 j 两个位子上的数, ...

  10. 【CodeForces 1100F】异或线性基 | 贪心 | 离线区间最大异或和 | E

    补题ing- 真的不应该错过这场比赛的 qwq 1100F. Ivan and Burgers time limit per test: 3 seconds memory limit per test ...

最新文章

  1. windows无法连接到打印机 操作失败,错误为0x00000002 解决方案
  2. MyStringUtil.java String工具类
  3. 【Unity3D基础】让物体动起来②--UGUI鼠标点击逐帧移动
  4. 【CodeForces - 467C】George and Job(dp,思维)
  5. Spring : @EnableConfigurationProperties注解
  6. C++ std::thread::hardware_concurrency() 获取CPU核心数
  7. Win7 可以下载python最高什么版本?
  8. BUUCTF [CISCN2019 总决赛 Day2 Web1] Easyweb
  9. ubuntu 18安装deepin下的QQ,微信等常用软件
  10. ps画画模糊笔刷_Photoshop绘图工具之模糊/锐化/涂抹工具
  11. 福禄克OTDR系列OFP-100-Q光纤测试仪
  12. 读懂西瓜书 14 : 概率图模型
  13. 论文阅读笔记《Robust Point Matching via Vector Field Consensus》
  14. 最简单的视音频播放演示样例4:Direct3D播放RGB(通过Texture)
  15. Python 爬取火车票信息(易于理解版)
  16. python之numpy之axis=1和axis=0
  17. 上期所SimNow使用指南
  18. matlab定义数组和相关函数
  19. Race_Condition_new
  20. Hue创建oozie workflow调度,Hue创建workflow,HUE配置邮件告警

热门文章

  1. 我国三大常用坐标系区别(北京54、西安80和WGS-84)
  2. 李航:做本质的、严谨的、有意思的研究,纪念我的导师长尾真教授
  3. ACL'22 | 基于强化学习的实体对齐
  4. 【ACL2021】三篇高质量方面级的情感分析方法解读
  5. 哈工大SCIR Lab | EMNLP 2019 结合单词级别意图识别的stack-propagation框架进行口语理解...
  6. 闲聊扯淡 | 微信8.0背景视频合集,笑死我了
  7. 深度学习2.0-9.tensorflow的高阶操作之填充与复制
  8. 提高应用程序可用性的五个要点
  9. C++Primer中文版(第5版)(顶级畅销书重磅升级 全面采用最新 C++ 11标准)
  10. 云计算能给你带来什么?