题目链接: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. extjs简单动画2

    var store = Ext.create('Ext.data.Store', { storeId:'employeeStore', fields:['name', 'seniority', 'de ...

  2. What is GSLB

    Global Server Load Balancing 中文:全局负载均衡 SLB(Server load balancing)是对集群内物理主机的负载均衡,而GSLB是对物理集群的负载均衡.这里的 ...

  3. Web Api单元测试写法

    例如我们在Web Api项目中有个Controller public class SomeController : ApiController { public HttpResponseMessage ...

  4. 本机ubuntu链接阿里云服务器(也是ubuntu)

    首先在本机安装ssh工具,并修改配置文件(参考:http://www.cnblogs.com/herd/p/5009067.html) 第一步:ssh 100.121.156.32(即:服务器的ip地 ...

  5. [转]PL/SQLDeveloper导入导出Oracle数据库方法

    原文地址:http://www.2cto.com/database/201405/305452.html 1.Oracle数据库导出步骤 1.1 Tools→Export User Objects.. ...

  6. [转]Servlet 中文乱码问题及解决方案剖析

    原文地址:http://blog.csdn.net/xiazdong/article/details/7217022/ 一.常识了解 1.GBK包含GB2312,即如果通过GB2312编码后可以通过G ...

  7. mysql-利润set变量模拟分组查询每组中的第N条数据

    查询思路: 很多时候想在使用group by时想查询group by的每一组中的第N条数据,而取这些数据时往往按如下方式去执行则很慢 ; 按如上方式,对于数据10000左右的表就已经很吃不消. 或已拼 ...

  8. sublime text 如何设置”在浏览器浏览“的快捷键

    sublime text编辑器极其强大 ,但在刚开始用的时候,每次在浏览器中查看非得右键鼠标----”open in browser“,着实觉得麻烦....百度之,上面的方法有很多,但是根据我自己的经 ...

  9. Xcode找不到模拟器出现"My Mac"

    问题如图: 步骤一. 找到target->built settings->Architectures->Base SDK, 选择你需要的版本;如果还是不行,看步骤二. 步骤二. 1) ...

  10. Enum遇到下拉框

    package com.zj.tool; public enum WeekDay { Mon(), Tue(), Wed(), Thu(), Fri(), Sat(), Sun(); /**定义枚举类 ...