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. 大数据实战centos 6.7安装mysql5.7

    https://www.cnblogs.com/jr1260/p/6590232.html

  2. 【Mac + ATX基于uiautomator2】使用weditor时,报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

    产生以下原因找到了:是因为启动了appium,两者冲突,不能同时使用. 之前讲过怎么安装u2([Mac安装,ATX基于uiautomator2]之安装步骤)以及使用weditor, 但是经过一段时间, ...

  3. VLine[-1]=VLine[width]=128 数组的负一地址代表啥

    最近在调算法是,涉及到rgb转yuv数据的一个函数,出现了这种常见错误:如下 unsigned char *VLine = (new unsigned char[width+2]);//+1;     ...

  4. dm8148 开发之---sii9022a hdmi传输器

    SiI9022A -HDMI 发送器    照相机.摄影机和便携式媒体播放器的高清解决方案   SiI9022a是一款超低功耗的HDMI发送器,集成度更高, 电源管理特性也更强,适用于手提式消费电子设 ...

  5. 我的消灭复杂password之行

    近期几天.网易一直提示邮箱账号异常.特意去查看了一下,发现须要改动password.可是经常使用的password又不让反复使用.于是无奈之下.就想办法消灭这些复杂password,由于实在是太难(g ...

  6. diamond源码阅读-循环探测配置信息是否变化rotateCheckConfigInfo

    rotateCheckConfigInfo 这是一个定时任务,循环调用 /** * 循环探测配置信息是否变化,如果变化,则再次向DiamondServer请求获取对应的配置信息 */ private ...

  7. 抒发一下这些天用django做web项目的一些体会

    最近接触了一段时间的python,觉得python写脚本还是挺方便的,做一个简单的桌面应用也很nice,但是随着深入,对python做功能复杂的web项目我彻底死心了​,每个环节都是一堆的坑,部署阶段 ...

  8. Unity3D学习笔记——初级知识

    一:Unity欢迎窗口对于初学者来说有很多有价值的信息,值得用户关注,以下将简要介绍这个窗口中的相关内容: 1.Video Tutorials: 提供unity相关的教程 ,包括用户手册 .组件手册以 ...

  9. 如何通过sequel pro导入.sql脚本

    1.参考地址     https://zhidao.baidu.com/question/985373253463808219.html

  10. keycode 大全,javascript 再也不用操心我不知道的keycode了

    keycode    8 = BackSpace BackSpace keycode    9 = Tab Tab keycode   12 = Clear keycode   13 = Enter ...