CodeForces - 1061A - Coins (贪心)

Coins

Time limit 2000 ms Memory limit 262144 kB

Problem Description

You have unlimited number of coins with values 1,2,,n1,2,…,n. You want to select some set of coins having the total value of SS.

It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum SS?

 

Input

The only line of the input contains two integers nn and SS (1n1000001≤n≤100000, 1S1091≤S≤109)

 

Output

Print exactly one integer — the minimum number of coins required to obtain sum SS.

 

Examples

Input
5 11
Output
3
Input
6 16
Output
3

Note

In the first example, some of the possible ways to get sum 1111 with 33 coins are:

  • (3,4,4)(3,4,4)
  • (2,4,5)(2,4,5)
  • (1,5,5)(1,5,5)
  • (3,3,5)(3,3,5)

It is impossible to get sum 1111 with less than 33 coins.

In the second example, some of the possible ways to get sum 1616 with 33 coins are:

  • (5,5,6)(5,5,6)
  • (4,6,6)(4,6,6)

It is impossible to get sum 1616 with less than 33 coins.

 

First Blood

既然有无限个1-n的硬币,那我肯定想尽量用大面值的硬币n啦,假设如果s不能整除n,那再添多张比n小的就行啦,int ans= ⌈ s/n ⌉=(s+n-1)/n=(int)(ceil(1.0*s/n)+0.1);

因为ceil(double)->int 需要+0.1控制精度,一般不推荐

另外我记得任意一个数n都可以用 连续的1.2.3.4...k 的某几项的和表示(可以用来贪心),只要 (1+k)*k/2 >=n(🦆哈哈)

 1 #include <cstdio>
 2 
 3 using namespace std;
 4 
 5 int main() {
 6     int n, s;
 7     scanf("%d%d", &n, &s);
 8     printf("%d\n", (s+n-1)/n);
 9     return 0;
10 }

 

posted @ 2019-02-18 19:01  SayGB  阅读(329)  评论(0编辑  收藏  举报