zoukankan      html  css  js  c++  java
  • C

    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代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int x,tmp,step=0,s[5]={5,4,3,2,1};
     5     cin>>x;
     6     for(int i=0;i<5;++i)
     7         if(x>=s[i]){step+=(tmp=x/s[i]);x-=tmp*s[i];}
     8     cout<<step<<endl;
     9     return 0;
    10 }
  • 相关阅读:
    2019.9.18 csp-s模拟测试46 反思总结
    2019.9.17 csp-s模拟测试45 反思总结
    矩阵求导(包含极大似然估计)
    sir
    Square into Squares. Protect trees!(平方数分解平方和)
    最小二乘法
    2.5&2.6 numpy&pandas 笔记
    2.4 python学习笔记
    2.3 python学习笔记
    2.1&2.2python学习笔记
  • 原文地址:https://www.cnblogs.com/acgoto/p/9150012.html
Copyright © 2011-2022 走看看