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)$的,需要优化,观察一下可以发现可以用过前缀和来优化. 我把 ...
随机推荐
- Python调用C可执行程序(subprocess) 分类: python 服务器搭建 C/C++ shell 2015-04-13 21:03 87人阅读 评论(0) 收藏
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn.os.popen.popen2.commands. ...
- mybatis05 用户添加
User.xml 向用户表插入一条记录. 主键返回 需求:user对象插入到数据库后,新记录的主键要通过user对象返回,这样就可以通过user获取主键值. 解决思路: 通过LAST_INSERT_I ...
- SCTP 关联的建立和终止
与TCP一样,SCTP也是面向连接的,因而也有关联的建立与终止的握手过程.不过SCTP的握手过程不同于TCP. 四路握手 建立一个SCTP关联的时候会发生下述情形(类似于TCP). (1)服务器必须准 ...
- Strtus2标签之<s:url>
Strtus2标签<s:url> 在没有使用Struts2的时候可以使用el来进行url传参.而在Struts2中不推荐使用el(其实在Struts2.0.0.11之后就不再支持el)而推 ...
- python学习笔记--导入tab键自动补全功能的配置
今天开始学习Python,必须配置tab键补全功能 1.首先我们需要查看python的安装路径 [root@abc ~]# python Python 2.6.6 (r266:84292, Jan 2 ...
- LCA问题
基本概念 LCA:树上的最近公共祖先,对于有根树T的两个结点u.v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u.v的祖先且x的深度尽可能大. RMQ:区间最小值查询问题.对于长度为n的 ...
- 数据库的CRUD操作
一:数据库的CRUD操作,C是指create新增,R是指retrieve检索,U是指update更改,D是指delete删除 SQL语句分为3类: 1.DDL指数据定义语言如:create,drop, ...
- 用Eclipse+xdebug调试PHP总是在首行自动断点解决方法
问题描述: 使用Eclipse+PDT+xdebug调试PHP程序时,总是在程序的第一行(首行)自动断点,不方便调试. 解决方法: 分别在下面3个位置配置,取消 Break at First Line ...
- 在后台CS文件里面,隐藏和显示Repeater里面控件
<asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><asp:Pa ...
- mvc5 + ef6 + autofac搭建项目(三)
前面已经基本完成了框架的搭建,后面就是实现了,后面主要说下前端的东西bootstrap的使用和相关插件. 看图: 实现比较简单,在主页面只引入共用部分的 js等相关包,毕竟不是所有页面都需要列表以及其 ...