Codeforces Round #340 (Div. 2)-A. Elephant(贪心)
2016-01-24 13:35
429 查看
A. Elephant
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
input
output
input
output
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.
思路:
这题就是一道贪心题,只要找出它是五的多少倍,而且能否被五整除就行了。
AC代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
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.
思路:
这题就是一道贪心题,只要找出它是五的多少倍,而且能否被五整除就行了。
AC代码:
#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<vector> #include<cstdio> #include<cmath> #include<set> using namespace std; #define CRL(a) memset(a,0,sizeof(a)) typedef unsigned __int64 LL; typedef __int64 ll; const int T = 3000100; const int mod = 1000000007; int main() { #ifdef zsc freopen("input.txt","r",stdin); #endif int n,m,i,j,k; while(~scanf("%d",&n)) { if(n%5!=0) printf("%d\n",n/5+1); else printf("%d\n",n/5); } return 0; }
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心法实现无向图的划分 代码
- 贪心题目循环和控制台折行
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- Codeforces Round #265 (Div. 2)
- HDOJ 1009
- Codeforces #310 div2 C. Case of Matryoshkas
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers