Codeforces Round #370 (Div. 2) C. Memory and De-Evolution
来源:互联网 发布:域名投资的秘密电子书 编辑:程序博客网 时间:2024/06/06 06:49
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side lengthx, and he wishes to perform operations to obtain an equilateral triangle of side lengthy.
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 lengthy?
The first and only line contains two integers x andy (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side lengthy if he starts with the equilateral triangle of side lengthx.
6 3
4
8 5
3
22 4
6
In the first sample test, Memory starts with an equilateral triangle of side length6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do .
In the second sample test, Memory can do .
In the third sample test, Memory can do:
.
题意:给你一个大等边三角形的边长和一个小等边三角形的边长,每次可以改变一个边的长度,但要求每次改变后仍然是一个三角形,问最少多少次可以把大三角形变成小三角形。
分析:正着直观分析有些难度,我们考虑倒着处理,把小的变大,每次选择小三角形的最小边变大,它最大变到另外两边和减一,这样不断迭代下去就可以了。
#include<iostream>#include<string>#include<algorithm>#include<cstdlib>#include<cstdio>#include<set>#include<map>#include<vector>#include<cstring>#include<stack>#include<cmath>#include<queue>#include <unordered_map>#define INF 0x3f3f3f3f#define eps 1e-9 #define MOD 1000000007 #define MAXN 100005using namespace std;typedef long long ll;typedef pair<int,int> pii;int main(){int x,y;scanf("%d%d",&x,&y);int a[3] = {y,y,y},num = 0;while(a[0] != x){a[0] = min(a[1] + a[2] - 1,x);sort(a,a+3);num++;}cout<<num<<endl;}
- Codeforces Round #370 (Div. 2)-C. Memory and De-Evolution
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【逆向思维+贪心】
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【逆向思维+贪心】
- 【Codeforces Round 370 (Div 2) C】【正难则反 贪心】Memory and De-Evolution
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【dfs+想法】
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution(数学,思维))
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution(逆向思维)
- codeforces 370div.2 C Memory and De-Evolution[逆向思维]【思维】
- codeforces C. Memory and De-Evolution
- Codeforces-712C-Memory and De-Evolution
- Codeforces 712C Memory and De-Evolution
- codeforces 712C C. Memory and De-Evolution(贪心)
- CodeForces 712C - Memory and De-Evolution 逆向思维
- 【Codeforces 712 C. Memory and De-Evolution】+ 贪心
- CodeForces 712 C. Memory and De-Evolution(贪心)
- [CF 712C] Memory and De-Evolution
- Codeforce - 712 -C. Memory and De-Evolution
- 2016 大连网络赛 HDU 5874 Friends and Enemies【思维】
- base64加密原理详解
- 非信任机构的https证书,afnetworking 会报错解决办法:
- 剑指offer - 面试题3:二维数组中的查找
- LeetCode 67. Add Binary
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution
- LeetCpde 246 -- Strobogrammatic Numbe I
- POJ 2289Jamie's Contact Groups 二分图多重匹配
- MySQL之——服务器调优思路
- Add Digits
- C语言scanf学习笔记
- 安卓(android)崩溃日志的抓取
- 编程之美。分层遍历二叉树(使用队列)
- JavaScript学习笔记