Created
September 9, 2016 19:32
-
-
Save lnrsoft/b3b08efdc5cca77d192a59393ce483db to your computer and use it in GitHub Desktop.
Chocolate Feast HackerRank Solution in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code written by Roland Ihasz | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
std::vector<int> vec; | |
void chockFunc(int nu, int co, int mn) | |
{ | |
int ch_qty; | |
int part_res1 = nu / co; | |
if(part_res1 >= mn) { | |
int part_res2 = part_res1 / mn; | |
if(((part_res1 + part_res2) / mn) >= 2) { | |
ch_qty = part_res1 + ((part_res1 + -1) / (mn - 1)); | |
} | |
if(((part_res1 + part_res2) / mn) < 2) { | |
ch_qty = part_res1 + part_res2; | |
} | |
} | |
if(part_res1 < mn) { | |
ch_qty = part_res1; | |
} | |
vec.push_back(ch_qty); | |
} | |
int main() | |
{ | |
int t, n, c, m; | |
std::cin >> t; | |
std::cin.ignore(); | |
while(t--) { | |
std::cin >> n >> c >> m; | |
chockFunc(n, c , m); | |
} | |
for(int i = 0; i < vec.size(); ++i) { | |
std::cout << vec[i] << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment