题目链接:http://codeforces.com/problemset/problem/712/C

题目大意:

  给连个值x,y (3 ≤ y < x ≤ 100 000), x,y都为等边三角形。从y等边三角形 每次修改一条边,且修改后的三个边还能组成一个三角形(两边之和大于第三边)。问修改几次能够得到x为边的等边三角形。

例如:

  输入: 22 4  输出: 6

  

解题思路:

  从y->x ,定义三个边y1=y2=y3=y,

  每次修改一条边 y1=y2+y3-1(两边之和大于第三遍) 修改++ 如果y1>=x break;

  修改一条边 y2=y1+y3-1 修改++ 如果y2>=x break;

  修改一条边 y3=y1+y2-1 修改++ 如果y3>=x break;

  可以发现,如果(y1,y2,y3)有一个边>=x,则还需两步即可完成。

  输出 修改+2

AC Code:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,ans;
while(scanf("%d%d",&x,&y)!=EOF)
{
ans=;
int y1,y2,y3;
y1=y2=y3=y;
while(y1!=x&&y2!=x&&y3!=x)
{
y1=y2+y3-;
++ans;
if(y1>=x)break;
y2=y1+y3-;
++ans;
if(y2>=x)break;
y3=y1+y2-;
++ans;
if(y3>=x)break;
}
cout<<ans+<<endl;
}
return ;
}

codeforces 712C C. Memory and De-Evolution(贪心)的更多相关文章

  1. CodeForces 712C Memory and De-Evolution (贪心+暴力)

    题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...

  2. Codeforces 712C Memory and De-Evolution

    Description Memory is now interested in the de-evolution of objects, specifically triangles. He star ...

  3. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  4. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  5. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  6. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  7. Codeforces 839B Game of the Rows【贪心】

    B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  8. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  9. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

随机推荐

  1. ubuntu 下mysql中文乱码问题解决方案

    mysql> show variables like 'character%';+--------------------------+----------------------------+ ...

  2. Region Representaion and Description

    两类特征 外部特征(external characteristics), 如boundary 内部特征(internal characteristics), 如像素, color, texture. ...

  3. lucene-Field.Store解析

    本文主要内容装载这里 Store 三种形态 COMPRESS:压缩保存.用于长文本或二进制数据 (后期高版本舍弃了) YES:保存 NO:不保存 具体案例 package demo.first; im ...

  4. js学习笔记7----return,arguments及获取元素样式

    1.return:返回值 1)函数名+括号:fn() ===> return; 2) 所有函数默认返回值:undefind; 3) return后面所有的代码都不会执行; 2.arguments ...

  5. 【HDU 5744】Keep On Movin

    找出奇数个的数有几个,就分几组. #include<cstdio> #include<cstring> #include<algorithm> #include&l ...

  6. 项目实例——多表关联查询判断A的字段是否在B中,在显示该字段值,不在显示空;B的字段是否在C中,在显示该字段值,不在显示空。

    1.需求: (1)三张表A.B.C  三个表id相同,如果A表中的name在B表中的bname中显示aname值,否则显示空:如果C表中的addr在B表中的tel显示addr,否则显示空 2.实现方式 ...

  7. 表头不动,内容滚动的例子(纯css+html)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. jquery插件-表单验证插件-提示信息中文化与定制提示信息

    接上一篇 2)messages 提示:修改默认的提示信息最简单的方法是引入message_zh.js文件即可! 如果需要在validate()方法内提示则可以使用本选项 类型:Object 说明:自定 ...

  9. Visual Studio多版本进行切换的研究

    最近在升级公司内部的项目到最新的开发工具Visual Studio 2015,可能在团队开发上会遇到这些问题: 1.团队成员的电脑和系统,设置安装的开发工具参差不齐 2.有些成员的Visual Stu ...

  10. Nuget包里的依赖包更新到最新版本会不会随主包回滚到旧包的研究

    A包中有几个依赖包:A-1包,版本:>=1.0:但是我项目上已经引用了A-1包的2.0版本,那么我添加A包的时候,不会将A-1包2.0版本改成1.0版本,会直接用2.0版本的.