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 ...
随机推荐
- mysql常用方法学习
环境 create table phople ( id int(11) not null primary key auto_increment, name char(20) not null, sex ...
- Java Native Method
一.什么是java native method? "A native method is a Java method whose implementation is provided by ...
- mysql-now()读取当日日期-格式化
使用系统时间now(): MYSQL 获取当前日期及日期格式获取系统日期: NOW() 格式化日期: DATE_FORMAT(date, format) 注: date:时间字段format:日期格式 ...
- ml的线性回归应用(python语言)
线性回归的模型是:y=theta0*x+theta1 其中theta0,theta1是我们希望得到的系数和截距. 下面是代码实例: 1. 用自定义数据来看看格式: # -*- coding:utf ...
- javaScript与MVC
MVC,就是Module,View,Controller分离,使业务逻辑更加清晰,但是现在公司的项目中很多地方那个不是这样的,很多业务逻辑放在了javascript中实现,这样做的优点就是对于技术要求 ...
- 【poj1160】 Post Office
http://poj.org/problem?id=1160 (题目链接) 题意 按照递增顺序给出一条直线上坐标互不相同的n个村庄,要求从中选择p个村庄建立邮局,每个村庄使用离它最近的那个邮局,使得所 ...
- bzoj1124[POI2008]枪战maf
这代码快写死我了.....死人最多随便推推结论.死人最少,每个环可以单独考虑,每个环上挂着的每棵树也可以分别考虑.tarjan找出所有环,对环上每个点,求出选它和不选它时以它为根的树的最大独立集(就是 ...
- wordpress /wp-content/plugins/wp-symposium/server/php/UploadHandler.php File Arbitrary Upload Vul
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Relevant Link:2. 漏洞触发条件3. 漏洞影响范围4. 漏 ...
- class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
今天在工作中遇到了下面的问题: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springfram ...
- django入门记录 1
步骤: 1 安装python和django 2 创建项目python-admin startproject mysite(此处可以替换) 3 至少需要一个数据表,所以要创建一个表 python ...