codeforces 712C C. Memory and De-Evolution(贪心)
题目链接: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(贪心)的更多相关文章
- CodeForces 712C Memory and De-Evolution (贪心+暴力)
题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...
- Codeforces 712C Memory and De-Evolution
Description Memory is now interested in the de-evolution of objects, specifically triangles. He star ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- 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 ...
- 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 ...
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- 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 ...
随机推荐
- android file path
问题 出现的异常为:java.lang.IllegalArgumentException: File /mnt/sdcard/crazyit.bin contains a pathseparator. ...
- MySQL的热备percona-xtrabackup、innobackupex的安装方法
http://blog.csdn.net/dbanote/article/details/13295727 http://blog.csdn.net/yangzhawen/article/detail ...
- 【POJ 3294】Life Forms 不小于k个字符串中的最长子串
一下午和一晚上都在刚这道题,各种错误都集齐了so sad 我的时间啊!!! 后缀数组就先做到这里吧,是在伤不起啊QAQ 出现了各种奇怪的错误,看了标算,然后乱改自己的代码,莫名其妙的改A了,后来发现用 ...
- css 导航,菜单对应页面切换效果实现方法
实现原理: 每个菜单有多个li标签,每个li标签含一个id,li标签的id用来标记:点击效果 每个页面有一个id,这个id的作用是对应每个li标签的点击链接对应的页面,它的作用是用来标记:li标签的h ...
- JS自动填写分号导致的坑
JS中会自动清除句子和句子之间的空格以及tab缩进, 这样就可以允许用户编写的代码更加随性和更加可读, 在该行代码解析的时候如果该行代码可以解析, 就会在该行代码最后自动填写分号,如果该行代码无法解析 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
- HTTP协议学习---(十)拓展-HTTPS协议
HTTPS(Hypertext Transfer Protocol over Secure Socket Layer,基于SSL的HTTP协议)使用了HTTP协议,但HTTPS使用不同于HTTP协议的 ...
- awk打印出当前行的上一行
#awk '/B/{print a;}{a=$0}' a.txt A # cat a.txt A BCDE
- php验证登录
<html><head> <title></title> <meta charset="utf-8"></head ...
- Maven项目自动生成mybaties配置文件
1.把mysql-connector-java-5.1.31.jar包放到C盘的mysqljar文件夹下 2.在generatorConfig.xml文件中配置实体.dao.service等包 < ...