Little Bob loves chocolates, and goes to the store with $N money in his pocket. The price of each chocolate is $C. The store offers a discount: for every M wrappers he gives the store, he'll get one chocolate for free. How many chocolates does Bob get to eat?

Input Format:
The first line contains the number of test cases T(<=1000).
T lines follow, each of which contains three integers N, C and M

Output Format:
Print the total number of chocolates Bob eats.

Constraints:
2≤N≤105


是有可能有多轮兑换的,比如N=10,C=3,M=2的时候,第一轮买到5个巧克力,用其中四个换回两块,此时手上一共有3个包装纸,第二轮换到1个巧克力,此时手上有两个包装纸,又可以换一块巧克力,一共兑换了3轮。

代码如下:

 import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*; public class Solution { public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; i++){
System.out.println(Solve(in.nextInt(), in.nextInt(), in.nextInt()));
}
} private static long Solve(int n, int a, int b){ //Write code to solve each of the test over here
int origin = n/a;
int total = origin;
while(origin/b>0){
int free = origin/b;
origin = free + origin%b;
total += free;
}
return total;
} }

【HackerRank】 Chocolate Feast的更多相关文章

  1. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  2. 【HackerRank】Running Time of Quicksort

    题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...

  3. 【HackerRank】Halloween party

    Change language : Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silv ...

  4. 【hackerrank】Week of Code 30

    Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...

  5. 【hackerrank】Week of Code 26

    在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...

  6. 【HackerRank】Median

    题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大 ...

  7. 【HackerRank】Coin on the Table

    题目链接:Coin on the Table 一开始想用DFS做的,做了好久都超时. 看了题解才明白要用动态规划. 设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的 ...

  8. 【HackerRank】Pairs

    题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...

  9. 【HackerRank】Cut the tree

    题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ...

随机推荐

  1. 微信强大的demo

    https://github.com/xialeistudio/wechatPublicPlatform

  2. C++实现文件关联

    下面这段话是百度百科对文件关联的解释. 文件关联就是将一种类型的文件与一个可以打开它的程序建立起一种依存关系.举个例子来说,位图文件(BMP文件)在Windows中的默认关联程序是“画图”,如果将其默 ...

  3. shell bash使用,包括判断文件或文件夹是否存在举例

    Linux shell编程——if条件判断 if [ condition ] ;then //一定要注意[] 與裡面的內容要有空格隔开 例如 if [(空格)${a} -eq 3(空格)]; then ...

  4. iOS ---APP更换应用图标logo

    iOS 10.3 加入了了更换应用图标的新功能,开发者可以为应用提供多个应用图标选择.用户可以自由的在这些图标之间切换,下面具体查看切换步骤. 1.先把你需要的所有图片都导入项目中(比例为1:1) 2 ...

  5. Laravel5.1 模型--ModelFactory

    今天要说的是模型工厂,它是可以快速生成一些测试数据的东西,之前我们介绍过Seeder,当我们使用模型访问数据时 可以用模型工厂搭配Seeder使用. 1 编写一个ModelFactory ModelF ...

  6. 《从零开始学Swift》学习笔记(Day 53)——do-try-catch错误处理模式

    原创文章,欢迎转载.转载请注明:关东升的博客 Swift 1.x的错误处理模式存在很多弊端,例如:为了在编程时候省事,给error参数传递一个nil,或者方法调用完成后不去判断error是否为nil, ...

  7. linux linux 互传文件 win 不通过 ftp sftp 往linux 传文件(文件夹)

    linux 传入 传出文件 swp  port  22 怎样通过swp通过docker 容器向外传文件 通过scp Linux互传文件,需要知道文件源 file source 所在系统的ip wuse ...

  8. JavaScript数据结构与算法-散列练习

    散列的实现 // 散列类 - 线性探测法 function HashTable () { this.table = new Array(137); this.values = []; this.sim ...

  9. Bootstrap Paginator分页插件+ajax

    Bootstrap Paginator分页插件下载地址: DownloadVisit Project in GitHub  Bootstrap分页插件属性介绍: http://www.cnblogs. ...

  10. 阿里巴巴java开发手册阅读笔记

    1. long 或者 Long 初始赋值时,必须使用大写的 L. Long a = 2L; 2. POJO 类(DO/DTO/BO/VO )必须写 toString 方法 3. final 可提高程序 ...