Codeforces Round #370 (Div. 2) C
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?
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:
.
题意:将一个大的等边三角形变为小的等边三角形,最小需要几步
解法:我们倒过来考虑要方便很多,先增加其中一条边到最大,然后增加第二条边,依次循环到大的等边三角形
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
int a,b,c;
int pos;
int cot=0;
cin>>n>>m;
a=m,b=m,c=m;
while(a!=n||b!=n||c!=n)
{
if(a!=n)
{
int pos1;
//cout<<"A"<<endl;
for(int i=1; i<=n; i++)
{
// cout<<"B"<<endl;
// cout<<a<<" "<<b<<" "<<c<<endl;
if((a+i)+b>c&&(b+c)>(a+i)&&(a+i)+c>b&&(a+i)<=n)
{
pos1=i;
// cot++;
}
}
a=a+pos1;
cot++;
// cout<<a<<endl;
// break;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// cout<<a<<" "<<b<<" "<<c<<endl;
// break;
if(b!=n)
{
int pos2;
for(int i=1; i<=n; i++)
{
// cout<<"B"<<endl;
if((b+i)+a>c&&(a+c)>(b+i)&&(b+i)+c>a&&(b+i)<=n)
{
// b=b+i;
pos2=i;
//cot++;
}
}
b=b+pos2;
cot++;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// cout<<a<<" "<<b<<" "<<c<<endl;
// break;
if(c!=n)
{
int pos3;
for(int i=1; i<=n; i++)
{
if((c+i)+a>b&&b+(c+i)>a&&b+a>c+i&&(c+i)<=n)
{
// cout<<i<<endl;
pos3=i;
// c=c+i;
// cot++;
} } c=pos3+c;
cot++;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// break;
// cout<<a<<" "<<b<<" "<<c<<endl;*/
}
cout<<cot<<endl;
return 0;
}
Codeforces Round #370 (Div. 2) C的更多相关文章
- 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 ...
- Codeforces Round #370 (Div. 2)B. Memory and Trident
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划
D. Memory and Scores 题目连接: http://codeforces.com/contest/712/problem/D Description Memory and his fr ...
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...
- Codeforces Round #370 (Div. 2) B. Memory and Trident 水题
B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...
- Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...
- Codeforces Round #370(div 2)
A B C :=w= D:两个人得分互不影响很关键 一种是f[i][j]表示前i轮,分差为j的方案数 明显有f[i][j]=f[i-1][j-2k]+2*f[i-1][j-2k+1]+...+(2k+ ...
- Codeforces Round #370 (Div. 2)(简单逻辑,比较水)
C. Memory and De-Evolution time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- CSS3 auto revolution practitioner!
1.html <!DOCTYPE html> <html> <head> <title></title> <meta charset= ...
- csuoj 1113: Updating a Dictionary
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 1113: Updating a Dictionary Time Limit: 1 Sec ...
- UML: 活动图
摘自http://www.umlonline.org/school/thread-36-1-1.html 活动图和流程图很类似,我们看看一个流程图的例子: 活动图是用来描述流程的一种图,它与流程图的不 ...
- Linux: .vimrc
set nuset autoindentset cindent"set tabstop=2"set shiftwidth=2set cursorlineset hlsearch&q ...
- 数据库中is null(is not null)与=null(!=null)的区别
在标准SQL语言(ANIS SQL)SQL-92规定的Null值的比较取值结果都为False,既Null=Null取值也是False.NULL在这里是一种未知值,千变万化的变量,不是“空”这一个定值! ...
- sql 存储过程 分页
ALTER PROCEDURE [dbo].[BrokerToLenderDataShow2]@Where VARCHAR(200), --查询条件 不含'where'字符,如id>10 and ...
- 解决xfce4桌面图标消失的问题
问题表现:panel还在,桌面的背景变成灰色,桌面图标消失,桌面右键没反映 解决方法:从登录管理器中登录另一个用户,发现桌面正常,猜测是由于家目录下的配置文件引起的. 删除 ~/.cache/sess ...
- yii2验证码的使用
1.控制器中 public function actions() { return [ 'captcha' => [ ...
- android蓝牙技术
配置权限 <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permiss ...
- Mongodb 笔记05 创建副本集
创建副本集 1. 副本集:副本集时一组服务器,其中有一个主服务器(primary),用于处理客户端请求:还有多个备份服务器(secondary),用于保存主服务器的数据副本.如果主服务器崩溃了,备份服 ...