HackerRank - Chocolate Feast

An iterative ‘simulation‘ problem:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int t, n, c, m;
    cin >> t;
    while (t--)
    {
        cin >> n >> c >> m;
        int answer = 0;
        // Computer answer
        answer = n / c;
        int wrapper = answer;
        while (wrapper >= m)
        {
            wrapper -= m;
            wrapper++;
            answer++;
        }
        cout << answer << endl;
    }
    return 0;
}
时间: 2024-11-03 21:42:56

HackerRank - Chocolate Feast的相关文章

【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 ge

HackerRank &quot;Chocolate in Box&quot; ?!

XOR -> 0 is the key (make it even pair): http://www.cnblogs.com/lautsie/p/3908006.html Something to learn about basic Game Theory: http://www.cdf.toronto.edu/~ajr/270/probsess/03/strategy.htmlYou can see, it is all about state(bit) toggling. #include

【HackerRank】Halloween party

Change language : Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silvia spots a giant chocolate bar. If the chocolate can be served as only 1 x 1 sized pieces and Alex can cut the chocolate bar exactly K times, what is

codeforces 598E E. Chocolate Bar(区间dp)

题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you ma

Bonetrousle HackerRank 数学 + 思维题

https://www.hackerrank.com/contests/world-codesprint-6/challenges/bonetrousle 给定一个数n,和k个数,1--k这k个,要求选择b个数,使得这b个数的和等于n. 首先考虑最小值,在1--k中选择前b个数,是最小的,记为mi.最大值,后b个数相加,记为mx 注意到一个东西:如果mi <= n <= mx.那么是绝对可行的.因为mi总能增加1(同时保证满足要求),所以在这个区间里面的,都是可行解. 所以首先从mi开始枚举,

hackerrank maxsum mod

https://www.hackerrank.com/challenges/maximise-sum/submissions/code/12028158 hackerrank 子数组和模m的最大值 时间复杂度nlgn, 主要是证明一点,presum[i]-presum[j] 对于0<j<i的j,最大的是第一个大于presum[i]的presum[j] 证明如下 Quro的讨论,感觉还是证明的过程不够细致 http://www.quora.com/What-is-the-logic-used-i

房价预测(HackerRank)

从今天开始要多做一些关于机器学习方面的竞赛题目,题目来源主要是Hackerrank和Kaggle.链接如下 Hackerrank:https://www.hackerrank.com/ Kaggle:https://www.kaggle.com/ 在Hackerrank中提交源代码,这就使得很多库都需要自己写,限制比较多.而Kaggle只需要提交数据,所以随便怎么搞都行.现在来讲第一道题,房价预测,这是Andrew Ng课程里的比较经典的例子.题目描述如下 题目:https://www.hack

CodeForces Round 279 D Chocolate

Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the second one is a2 × b2 segments large. Polycarpus wants to give Paras

【HackerRank】Median

题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大堆存放前半部分较小的元素,最小堆存放后半部分较大的元素,并且最大堆的所有元素小于最小堆的所有元素:保持最大堆最多比最小堆多一个元素.每次插入元素的时候都先插入到最大堆,如果发现最大堆比最小堆多了两个个,那么就从最大堆里面拿出最大的放到最小堆里面:如果发现最大堆里面新插入的元素破坏了最大堆所有元素小于