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 ...
随机推荐
- CentOS-6.5安装zabbix2.4.4
使用epel源 (检查网络连接是否正常) //这里使用epel源 [root@localhost /]# wget -O /etc/yum.repos.d/CentOS-Base.repo ht ...
- Ehcache与Guava Cache的区别浅谈
最近在做一些缓存改造的场景,有如下一些经验总结: 缓存版本: Ehcache:2.8.3 Guava:17.0 Ehcache支持持久化到本地磁盘,Guava不可以: Ehcache有现成的集群解决方 ...
- Inorder Successor in Binary Search Tree
Given a binary search tree (See Definition) and a node in it, find the in-order successor of that no ...
- Laravel 5.1 文档攻略 —— Eloquent Collection
简介 像all()和get(),还有一些处理模型关系这种会返回多条数据的方法,在Eloquent里面会返回一个collection对象集合(对象装在对象里),而不是像DQB的数组结果集合(对象装在数组 ...
- 分治法避免定义多个递归函数,应该使用ResultType
总结:对二叉树应用分治法时,应避免定义多个递归函数,当出现需要递归求解多种的结果时,尽量使用ResultType来让一次递归返回多种结果. 题目:Binary Tree Maximum Path Su ...
- django xadmin 插件(1)
1. 插件的作用可以是全局的,也可以是只针对某个模型的.通过其 init_request控制是否加载此插件, demo如下: class SCPCardOverviewPlugin(BaseAdmin ...
- ubuntu14 谷歌输入法
sudo apt-get install ibus-googlepinyin 装完重启即可: (在右上角语言处右键,添加text entry)
- PE556
考虑推广sum(i in Z){mu^2(i)}的做法. #include"roundCount.cpp" #include<cstdio> #include<v ...
- Arp攻击实战
hyddd原创,转载请说明出处. 现在网上很多关于ARP攻击的文章,但多数是描述其原理,少数会以某个工具作为例子展开说明,但感觉说的还是不够详细,今天写个文章以实战介绍一个叫"WinArpA ...
- ionic 接触的第一个Hybrid项目
最近需要维护一个Hybird项目,使用的是ionic,由于是第一个Hybrid项目,在这里记录下基本的知识. 先看一下ionic的最基本介绍: http://my.oschina.net/u/2275 ...