C - Elephant(贪心)
Problem description
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input
The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.
Output
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
Examples
Input
5
Output
1
Input
12
Output
3
Note
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.
解题思路:从起始点0出发到达终点x,输出这一过程所走的最少步数。做法:从大的步数往小的步数贪心即可,水过。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,tmp,step=,s[]={,,,,};
cin>>x;
for(int i=;i<;++i)
if(x>=s[i]){step+=(tmp=x/s[i]);x-=tmp*s[i];}
cout<<step<<endl;
return ;
}
C - Elephant(贪心)的更多相关文章
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
题意: 有一种个位数与最高位数字相等的数字,求在l,r的范围内,这样的数字的个数. 思路: 找下规律就知道当当n>10的时候除去个位以后的答案等于n/10,然后考虑第一个数字是否小于最后一个.小 ...
- POJ - 2965 - The Pilots Brothers' refrigerator (高效贪心!!)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19356 ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
随机推荐
- JAVA软件工程师应该具备哪些基本素质?
必知:软件企业要求基础软件工程师具备六大基本素质,即良好的编码能力.自觉的规范意识和团队精神.认识和运用数据库的能力.较强的英语阅读和写作能力.具有软件工程的概念和求知欲和进取心. 1.良好的编码能力 ...
- PCL:描述三维离散点的ROPS特征(Code)
前言: 三维点云为三维欧式空间点的集合.对点云的形状描述若使用局部特征,则可分为两种:固定世界坐标系的局部描述和寻找局部主方向的局部描述,ROPS特征为寻找局部主方向的特征描述. 1.寻找主方向(对X ...
- Python学习①. 基础语法
Python 简介 Python 是一种解释型,面向对象的语言.特点是语法简单,可跨平台 Python 基础语法 交互式编程 交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编 ...
- monkey测试环境搭建 及 操作步骤
1.环境搭建 a.下载安卓SDK 链接:https://pan.baidu.com/s/1-OB6UVPvl5-N-vFdykfMmA 提取码:3spx b.配置环境变量(配置完成,重启系统,配置生效 ...
- android keystore的生成和使用
android要求所有的程序必须有签名,否则就不会安装该程序.在我们开发过程中,adt使用debug keystore,在 preference->android->buid中设置.deb ...
- 第2章 this 、 call 和 apply
第一部分 基础知识 第2章 this . call 和 apply 2.1 this JavaScript的 this 总是指向一个对象,而具体指向哪个对象是在运行时基于函数的执行环境动态绑定的, ...
- python爬虫08 | 你的第二个爬虫,要过年了,爬取豆瓣最受欢迎的250部电影慢慢看
马上就要过年啦 过年在家干啥咧 准备好被七大姑八大姨轮番「轰炸」了没? 你的内心 os 是这样的 但实际上你是这样的 应付完之后 闲暇时刻不妨看看电影 接下来咱们就来爬取豆瓣上评分最高的 250部电影 ...
- Codeforces 912A/B
A. Tricky Alchemy 传送门:http://codeforces.com/contest/912/problem/A 参考程序如下: #include <stdio.h> # ...
- Redis启动出错 noauth authentication required.
输入认证过的密码即可. 在命令行中运行: auth password
- 8.在idea中配置maven
1.在IntelliJ IDEA中配置maven 打开-File-Settings 2.我们还可以在勾选一些其他选项 3.我们可以更新一下本地仓库和远程仓库,这个样在pom.xml文件中添加依赖jia ...