【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 ...
随机推荐
- PHP测试与优化(1)-- Apache自带的压力测试工具ab(apache bench) - 简单使用
ab是apache自带的网站压力测试工具,能够测试网站在一定时间内的发生高并发时的反应. 使用 1.进入apache的bin文件夹 2.模拟并发级别为100,请求数为1000个的api数据请求数量测试 ...
- 用记事本写的java程序引用jar文件
1.将须要用的jar文件和java程序复制到同一个文件文件夹下 2.进行编译.编译的命令:javac -cp log4j-1.2.15.jar A.java 3.进行运行.运行的命令:java -cp ...
- 检测进程不存在自动重启shell脚本
#!/bin/bash WORKDIR="/usr/local/gse/gseagent" [[ -d $WORKDIR ]] && { if ! ps aux|g ...
- ChemDraw 15支持哪些输入格式
当我们想让我们的化学图形应用在试卷编辑.论文撰写.刊物出版等各个方面,这个时候往往都得使用ChemDraw 15.它可以与很多第三方应用灵活.本ChemDraw教程介绍新版ChemDraw Profe ...
- win10输入法设置
控制面板中: ok.
- PHP POST, GET 参数过滤,预防sql注入函数
1. 实际过滤函数 可适当修改其中的正则表示式 1 static public function filterWords(&$str) 2 { 3 $farr = array( 4 " ...
- 43、android:screenOrientation
android:screenOrientationThe orientation of the activity's display on the device. The value can be a ...
- Android UI开发第二十九篇——Android中五种常用的menu(菜单)
Android Menu在手机的应用中起着导航的作用,作者总结了5种常用的Menu. 1.左右推出的Menu 前段时间比较流行,我最早是在海豚浏览器中看到的,当时耳目一新.最早使用左右推出菜单的,听说 ...
- 【BZOJ3995】[SDOI2015]道路修建 线段树区间合并
[BZOJ3995][SDOI2015]道路修建 Description 某国有2N个城市,这2N个城市构成了一个2行N列的方格网.现在该国政府有一个旅游发展计划,这个计划需要选定L.R两列(L&l ...
- mongodb安全配置
1. 为数据库增加管理员 use admin db.createUser({ >user:'userName', pwd:'password', roles:[{role:'userAdminA ...