Codeforces Round #370 (Div. 2)(简单逻辑,比较水)
2 seconds
256 megabytes
standard input
standard output
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的等边三角形;
思路:
从y往x反推,用数组a存储当前边的状态,每次让最小边变成最长边,由公理:三角形的最长边小于另两边之和得a[0]=a[1]+a[2]-1;
注意边界条件x, 即a[0]=min(a[1]+a[2]-1, x);
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std; int main(void)
{
int x, y;
ll ans=;
cin >> x >> y;
int a[];
a[]=a[]=a[]=y;
while(a[]<x)
{
ans++;
a[]=min(a[]+a[]-, x);
sort(a, a+);
}
cout << ans << endl;
return ;
}
苦难归于我,荣耀和鲜花也将归于我; ------ geloutingyu
Codeforces Round #370 (Div. 2)(简单逻辑,比较水)的更多相关文章
- Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #370 (Div. 2) A , B , C 水,水,贪心
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心
地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...
随机推荐
- Java中String和Int的相互转换
一.将字串 String 转换成整数 intA. 有2个方法:1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([Strin ...
- Javascript高级程序设计——执行环境与作用域
Javascript中执行环境是定义了变量或函数有权访问的其他数据,决定了各自的行为,每个执行的环境都有一个与之关联的变量对象,环境中定义的所以变量和函数都保存在这个对象中. 全局执行环境是最外围的一 ...
- 第一篇博客 iframe自适应高度
$('iframe').load(function(){ $(this).height($(this).contents().find(document).height())})这样就适应里面内 ...
- Android学习笔记(五)——活动的生命周期
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 为了能写出流畅连贯的程序,我们需要了解一下活动的生命周期. 一.返回栈 Android 中的活动是可以层叠的. ...
- phpcms如何判断用户是否登录
首先要获取userid <?php $userid= param::get_cookie('_userid'); ?> 然后再判断是否为空 {if $userid} ...
- 在Fedora 20 上安装Mysql并初始化root密码
[root@localhost ~]# yum -y install community-mysql-server #安装数据库 已加载插件:langpacks, refresh-packagekit ...
- Sqli-LABS通关笔录-10
好像咋整都没辙.实在是关卡越高越不好整. 弄报错.咋整咋不报错. and sleep(10);鸭蛋的也不好搞.实在没辙.就看源码了. 由代码得出payload: THE END
- 一起入门python3之元组和数列
这一节我们来说一下,元组(tupe)&数列(list).每天苦逼的工作不易啊,哎.不过呢一腔热血学习.哈哈哈哈 #井号代表注释哈. 0x01 数列-list 数列可以说是一种集合 ...
- 4.6---找二叉树中序后继(CC150)
因为,没有重复值,所以只需要做一个标记就OK了. public class Successor { static boolean flag = false; static int result = 0 ...
- Linux--多网卡的7种Bond模式
网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是一种常用的技术,我们公司基本所有的项目相关服务器都做了bond,这里总结整理,以便待查. bond ...