Codeforces 712C Memory and De-Evolution
Description
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 \le y < x \le 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\).
Sample Input
22 4
Sample Ouput
6
我还是too old了。怎么都没想出正的怎么贪心,改了1.5h。TM正解居然是逆向思考,从\(y\)到\(x\),最佳的方法肯定是用边界三角形来每次更新一条边\((a = b+c-1)\),这样子轮流更新三角形变大最快,以此来贪心。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int aim,l[3],res = 3,ans;
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
scanf("%d %d",&aim,&l[0]); l[1] = l[2] = l[0];
while (res)
{
for (int i = 0;i < 3&&res;++i)
{
l[i] = l[(i+1)%3]+l[(i+2)%3]-1; ++ans;
if (l[i] >= aim) --res,l[i] = aim;
}
}
printf("%d",ans);
fclose(stdin); fclose(stdout);
return 0;
}
Codeforces 712C Memory and De-Evolution的更多相关文章
- CodeForces 712C Memory and De-Evolution (贪心+暴力)
题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...
- codeforces 712C C. Memory and De-Evolution(贪心)
题目链接:http://codeforces.com/problemset/problem/712/C 题目大意: 给连个值x,y (3 ≤ y < x ≤ 100 000), x,y都为等边三 ...
- codeforces 712B. Memory and Trident
题目链接:http://codeforces.com/problemset/problem/712/B 题目大意: 给出一个字符串(由'U''D''L''R'),分别是向上.向下.向左.向右一个单位, ...
- codeforces 712A. Memory and Crow
题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi + ...
- Codeforces 712E Memory and Casinos
Description There are n casinos lined in a row. If Memory plays at casino \(i\), he has probability ...
- CodeForces 712B Memory and Trident (水题,暴力)
题意:给定一个序列表示飞机要向哪个方向飞一个单位,让你改最少的方向,使得回到原点. 析:一个很简单的题,把最后的位置记录一下,然后要改的就是横坐标和纵坐标绝对值之和的一半. 代码如下: #pragma ...
- CodeForces 712A Memory and Crow (水题)
题意:有一个序列,然后对每一个进行ai = bi - bi + 1 + bi + 2 - bi + 3.... 的操作,最后得到了a 序列,给定 a 序列,求原序列. 析:很容易看出来,bi = ai ...
- [CodeForces - 712D]Memory and Scores (DP 或者 生成函数)
题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高. ( ...
- CodeForces 712D Memory and Scores
$dp$,前缀和. 记$dp[i][j]$表示$i$轮结束之后,两人差值为$j$的方案数. 转移很容易想到,但是转移的复杂度是$O(2*k)$的,需要优化,观察一下可以发现可以用过前缀和来优化. 我把 ...
随机推荐
- GUI编程笔记(java)02:java.awt和java.swing包的区别
1. java.awt和java.swing两者的概述 java.awt:(java的标准包) Abstract Window ToolKit (抽象窗口工具包),需要调用本地 ...
- springmvc使用aop心得
第一步:创建aop拦截类: @Component @Aspect public class ControllerSelectorInterceptor { @Before("executio ...
- maven 创建web项目
1,新建一个web项目 2,构建基础目录 web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web A ...
- C#入门教程(三)–接收用户输入、转义字符、类型转换-打造C#入门教程
上次教程主要讲解了visual stdio快捷键.变量相关的知识.具体教程戳这里:http://www.chengxiaoxiao.com/net/1027.html 越来越深入去写教程越来越发现,自 ...
- Bootstrap--全局css样式之表单
单独的表单控件会被自动赋予一些全局样式.所有设置了 .form-control 类的 <input>.<textarea> 和 <select> 元素都将被默认设置 ...
- PHP的数据库 之 关闭问题
首先,PHP由于有垃圾回收机制,所以数据库即使你不手动关闭,也有自动去关闭的机制, 这里就和操作文本流不同,文本流需要手动去关闭,不然会发生内存浪费现象 并且,PHP在同时连接多个DB的时候,连接到一 ...
- PHP 数组的值插入
曾今写过一个坑货的数组方法 function array_insert($myarray,$value,$position=0) { $fore=($position==0)?array():a ...
- SQL Server数据类型
转载:http://www.ezloo.com/2008/10/sql_server_data_type.html 数据类型是数据的一种属性,是数据所表示信息的类型.任何一种语言都有它自己所固有 ...
- Update Statistics用法
Update Statistics语句的作用将创建的数据库表的有关统计信息更新到系统 sysmater的相关表中,以便查询优化器选择最佳的执行路径,当sysmaster库中没有相应的统计信息,或者统计 ...
- Android - 获取字符串长度的宽度
Paint paint = new Paint(); float strWidth = paint.measureText(String);