题解 | #访友#
访友
http://www.nowcoder.com/practice/b8e21f5816874425836b7d32011f46b0
本弱菜就给C党发一份题解吧。
首先,道理很简单:贪心算法。
既然是最大值,那就5步5步地走呗!
不足5步的,再走一次就了(liao)了(le).
计算步数的代码如下:
int ans=n/5; if(n%5!=0) ans++;有了思路,就可以上代码了(^_^)
(本弱菜的代码可能有些繁琐,各位神犇不喜勿喷)
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int ans=n/5;
if(n%5!=0) ans++;
cout<<ans;
return 0;
}
<stron>再走吧,谢谢!!! </stron>
查看29道真题和解析