#include <iostream> int hh(int buyNeed, int screepNeed, int need) { int buyNeed = 0; int…
- User
#include
int hh(int buyNeed, int screepNeed, int need) { int buyNeed = 0; int screepNeed = 0;
std::cin >> buyNeed; std::cin >> screepNeed; int need; std::cin >> need; // покупаем int plusBuy = need % buyNeed; // точим int plusSc = (need + plusBuy) % screepNeed; return (need + plusBuy + plusSc);} int main() { int a = 0; std::cin >> a; int b = 0; std::cin >> b; int c = 0; std::cin >> c;
}
Сделай перебор по условию, меняй только main
Технология производства некоторой металлической детали предполагает вытачивание её из металлической заготовки. При этом образуются стружки, которые не стоит выкидывать. Ведь из а комплектов стружек (оставшихся после обработки а заготовок) можно бесплатно выплавить еще одну заготовку, которую снова можно использовать для выточки детали и создания ещё одного комплекта стружек Заготовки можно купить на оптовом складе, при этом в целях привлечения клиентов, проводится акция «купи заготовок, тогда еще одну получишь бесплатно“. Требуется изготовить с деталей. Нужно определить мигммальное число заготовок, которые нужно купить за деньги, чтобы с учетом бонусных заготовок и экономии на стружкак можно было изготовить требуемое число деталей
- Assistant
To solve the problem of finding the minimum number of raw parts you need to buy, considering the promotions and recycling options, we can simulate the process using a loop until we've produced enough parts. The task can be broken down into the following steps:
-
Initialization: Start with a counter for parts we've crafted and for how many raw parts we've bought.
-
Recycle and Bonus: After using every
aparts you've crafted (including bonus parts), you directly gain one bonus part due to the recycling process. Also, every batch you buy gives you an additional part due to the promotionb. -
Crafting Loop: Continue crafting parts while you haven't met your goal of
cparts.
Here's how we can implement it:
#include <iostream> int main() { int a, b, c; std::cin >> a >> b >> c; // Input for recycling, bonus, and parts needed. int partsMade = 0; int rawPartsBought = 0; int totalRawParts = 0; while (partsMade < c) { // Increment the number of raw parts bought. rawPartsBought += 1; // With each purchase, you get 1 bonus raw part. totalRawParts += (b + 1); // Use while you still have enough raw parts to craft at least one part // If we use one raw part, produce one finished part and gain a quota of scrappy metal. // From every `a` parts you "use", get one more raw part for free (scrappy recycling rule). partsMade += totalRawParts; totalRawParts -= partsMade / a; } // rawPartsBought is the minimal number of parts you actually need to buy std::cout << rawPartsBought << std::endl; return 0; }Steps to run this program:
- Compile it using a C++ compiler, e.g.,
g++. - Run the executable.
- Input the three integers separated by space:
abandcwhen prompted.
Explanation:
- Initialization: Start with zero crafted parts.
- Loop: Each loop iteration represents buying one batch of
bparts:- Add
b + 1to your raw stock because of the bonus. - Calculate how many parts you can craft (
totalRawParts) and how many "scrap" bonus parts you generate for eachaparts crafted.
- Add
- Termination: The loop stops when you've crafted at least
cparts.
This solution ensures that you purchase the minimum possible parts while maximizing bonuses and recycling.
-