【HackerRank】 Chocolate Feast
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的更多相关文章
- 【HackerRank】How Many Substrings?
		https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ... 
- 【HackerRank】Running Time of Quicksort
		题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ... 
- 【HackerRank】Halloween party
		Change language : Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silv ... 
- 【hackerrank】Week of Code 30
		Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ... 
- 【hackerrank】Week of Code 26
		在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ... 
- 【HackerRank】Median
		题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大 ... 
- 【HackerRank】Coin on the Table
		题目链接:Coin on the Table 一开始想用DFS做的,做了好久都超时. 看了题解才明白要用动态规划. 设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的 ... 
- 【HackerRank】Pairs
		题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ... 
- 【HackerRank】Cut the tree
		题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ... 
随机推荐
- Web前端都学点儿啥?
			Web开发如今是如日中天,热的发烫.但是Web开发相关的技术和知识却像N座大山一样,耸立在我们面前,连绵起伏,漫无边际.那么这些山头那些我们应该占领,那些我们应该绕开,很多人看着就蒙了,这不光是初学者 ... 
- Eclipse Debug 配置
			创建和使用 Debug 配置 Eclipse Debug 配置类似于运行配置但它是用于在调试模式下开启应用. 打开 Debug 配置对话框步骤为:Run > Debug Configuratio ... 
- 怎样在asp.net中用一般处理文件ashx实现下载功能
			/// <summary> /// 下载文件,支持大文件.续传.速度限制.支持续传的响应头Accept-Ranges.ETag,请求头Range . /// Accept-Ranges:响 ... 
- 测试kernel.pid_max值
			# sysctl kernel.pid_max kernel.pid_max = # sysctl - kernel.pid_max = #include <unistd.h> #incl ... 
- tomcat NIO配置
			1.tomcat NIO配置 今天在查看日志时发现tomcat的Socket连接方式为bio,于是我想既然有bio那肯定有nio.果然,一查就发现tomcat在6.0之后就可以配置nio的方式.nio ... 
- 误: Apache shutdown unexpectedly解决办法
			from:http://www.wopus.org/wordpress-basic/getting-started/2536.htmlXAMPP错 2015年10月20日15:58:19 新手上路发 ... 
- JS中的关键字和保留字
			JavaScript中不能作为变量名的关键字和保留字总结: 1.js中的关键字: break case catch continue default delete do else finally fo ... 
- 【BZOJ3158】千钧一发 最小割
			[BZOJ3158]千钧一发 Description Input 第一行一个正整数N. 第二行共包括N个正整数,第 个正整数表示Ai. 第三行共包括N个正整数,第 个正整数表示Bi. Output 共 ... 
- javascript中字符串截取的两种方法
			var testStr = "hello kay!"; 1.substr testStr.substr(1) ->ello kay! testStr.substr(1,4 ... 
- iOS 成员变量和属性的区别
			一. 成员变量 1.成员变量的作用范围: @public:在任何地方都能直接访问对象的成员变量 @private:只能在当前类的对象方法中直接访问,如果子类要访问需要调用父类的get/set方法 @p ... 
