codeforces 712C C. Memory and De-Evolution(贪心)
来源:互联网 发布:问卷调查数据分析 编辑:程序博客网 时间:2024/06/06 04:27
Description
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?
Input
The first and only line contains two integers x andy (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 lengthy if he starts with the equilateral triangle of side lengthx.
Sample Input
6 3
4
8 5
3
22 4
6
Sample Output
Hint
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<algorithm>using namespace std;int main(){int x,y;cin >> x >> y;int arr[6];arr[0]=y;arr[1]=y;arr[2]=y;int ans=0;while(1){sort(arr,arr+3);if(arr[1]+arr[2]>x){ arr[0] = x; ans++;} else { arr[0] = arr[1]+arr[2]-1; ans++;} if(arr[0]==arr[1]&&arr[1]==arr[2]) break;}cout << ans << endl;return 0;}
- codeforces 712C C. Memory and De-Evolution(贪心)
- 【Codeforces 712 C. Memory and De-Evolution】+ 贪心
- CodeForces 712 C. Memory and De-Evolution(贪心)
- Codeforces-712C-Memory and De-Evolution
- Codeforces 712C Memory and De-Evolution
- codeforces C. Memory and De-Evolution
- CF 712C. Memory and De-Evolution 贪心
- Codeforces Problem 712C Memory and De-Evolution(贪心,逆推)
- CodeForces 712C - Memory and De-Evolution 逆向思维
- [CF 712C] Memory and De-Evolution
- Codeforce - 712 -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
- CodeForces 712C Memory and De-Evolution(逆推,新思路)
- codeforces 712-C. Memory and De-Evolution(数学+逆推)
- IP头,TCP头,UDP头,MAC帧头定义
- swift中跳转WKWebView 链接不含汉字的写法
- poj1088(记忆化搜索)
- 红宝书-日N3-文字词汇-1
- [深入剖析React Native]热更新之react-native-pushy使用指南(Android)
- codeforces 712C C. Memory and De-Evolution(贪心)
- React Native error “Could not get BatchedBridge
- Kinect Fusion 的处理流程 工作原理
- enum枚举
- Zookeeper 集群配置
- MySQL外键约束中几个值的含义
- IT须知的几个网站
- 基于BaseAdapter扩展的服务器数据与本地视图绑定适配器
- 堆和栈的区别(转过无数次的文章)