题目链接: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. MySQL server PID file could not be found!

    重启mysql提示MySQL server PID file could not be found! Starting MySQL...The server quit without updating ...

  2. MyBatis学习总结

    1.引入jar包到lib目录下:只需要mybatis的一个mybatis.jar及数据库的jar包. 2.在src下新建xml配置文件,即上图中的conf.xml <?xml version=& ...

  3. iOS开发小技巧--学会包装控件(有些view的位置由于代码或系统原因,位置或者尺寸不容易修改或者容易受外界影响)

    一.百思项目中遇到了两处这样的问题, 第一处 - 是评论界面的headerView,由于直接把自己搞的xib加载了放在了那里,xib中setFrame写了好多-=  +=,每次滚动的时候,会频繁调用x ...

  4. Shiro 学习笔记(一)——shiro简介

    Apache Shiro 是一个安全框架.说白了,就是进行一下 权限校验,判断下这个用户是否登录了,是否有权限去做这件事情. Shiro 可以帮助我们完成:认证.授权.加密.会话管理.与web 集成. ...

  5. 数组与指针-----a[i]=*(a+i)=i[a]

    #include<stdio.h> #include<stdlib.h> int main(void) { ,,,,};//a[i]相当于*(a+i) printf(]); p ...

  6. bzoj4337: BJOI2015 树的同构

    hash大法好 #include <iostream> #include <cstdio> #include <cstring> #include <cmat ...

  7. 自定义cell的一些知识

    1.要往cell里面添加一个自定义的子控件,都是添加到cell的contentView,不是添加到cell里面. 2.通过xib自定义cell * 添加tableView * 加载团购数据 * 新建x ...

  8. Leetcode 280. Wiggle Sort

    Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...

  9. 几个pointer

    [备份]了解initramfs,越往深处走觉着需要了解的东西越多,所以干脆回来,从实际系统的实现开始寻迹.在学习的这个系统中,里面用了busybox,实现的系统可谓精简之又精简.早上主要学习了root ...

  10. MVC5-5 Razor引擎及视图结构

    View结构 其实给我们提供了官方的MvcDemo,就是在我们直接去新建一个不为空的MVC项目. 这里就是一个MVC的Demo了,可以看一下这个Demo中View的结构是什么 上图可以发现,有一个Sh ...