本文共 484 字,大约阅读时间需要 1 分钟。
题目来源:
Description
这里有无限多的硬币,每个硬币的价值从 1, 2, …, n。需要从中拿出一些来,使总价值等于 S。
最少需要多少个硬币?Input
输入仅一行,有两个整数 n 和 S(1 ≤ n ≤ 105, 1 ≤ S ≤ 109)。
Output
输出准确的一个整数,表示用最少的硬币数量让总价值等于 S。
Sample Input
6 16
Sample Output
3
AC代码:
#includeusing namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'int main(){ SIS; int n,s; cin >> n >> s; int ans=s/n; if(s%n) ans++; cout << ans << endl; return 0;}
转载地址:http://tsyof.baihongyu.com/