CF#712 C. Memory and De-Evolution(水题)
来源:互联网 发布:java 自动生成代码 编辑:程序博客网 时间:2024/06/14 10:06
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?
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.
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.
6 3
4
8 5
3
22 4
6
In the first sample test, Memory starts with an equilateral triangle of side length 6 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:
.
题意:将一个边长为X的等边三角形缩小为一个边长为Y的等边三角形,每次只能修改一条边且修改过程中三边始终能构成三角形,问至少修改几次?
思路:贪心加上逆向思维,把小三角形转变为大三角形,每次将最短的边修改为最长且合法的边。
#include<bits/stdc++.h>using namespace std;int main(){ int x,y; while(scanf("%d%d",&x,&y)==2) { int sum=0; int a1,a2,a3; a1=a2=a3=y; while(a1<x) { a1^=a2^=a1^=a2; a2^=a3^=a2^=a3; a3=a1+a2-1; sum++; } printf("%d\n",sum); }}
- CF#712 C. Memory and De-Evolution(水题)
- [CF 712C] Memory and De-Evolution
- CF#712 C. Memory and De-Evolution (数学)
- CF 712C. Memory and De-Evolution 贪心
- Codeforces-712C-Memory and De-Evolution
- Codeforces 712C Memory and De-Evolution
- Codeforce - 712 -C. Memory and De-Evolution
- CodeForces 712 C. 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 C. Memory and De-Evolution
- CodeForces 712C Memory and De-Evolution(逆推,新思路)
- codeforces 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 Problem 712C Memory and De-Evolution(贪心,逆推)
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution(数学,思维))
- Three.js进阶篇之9
- 【3月27日】手撕架构(一)使用IDEA创建Maven项目
- ip over sdh
- iOS学习笔记-066.事件传递——查找合适的view
- hashCode 和 equals 正确用法和需要注意的地方(面试基本都会问)
- CF#712 C. Memory and De-Evolution(水题)
- LintCode-链表倒数第n个节点
- [visual-studio]Temp 路径太长,发布一个网站项目时
- Xshell无法连接Ubuntu14
- linux练习题4
- 1012. 数字分类 (20)-PAT乙级
- LintCode-删除排序链表中的重复元素
- POJ 1321
- 初识Markdown