Codechef nuclear reactors question

Source: Internet
Author: User

There are K nuclear reactor Chambers labeled from 0 to K-1. participant are bombarded onto Chamber 0. the participating keep collecting in the Chamber 0. however if at any time, there are more than N participant in a chamber, a reaction will cause 1 particle to move to the immediate next chamber (if current chamber is 0, then to chamber number 1), and all the participants in the current chamber will be destroyed and same continues till no chamber has number of participant greater than N. given k, n and the total number of particles bombarded (A), find the final distribution of particles in the K chambers. participant are bombarded one at a time. after one particle is bombarded, the set of reactions, as described, take place. after all reactions are over, the next particle is bombarded. if a particle is going out from the last chamber, it has nowhere to go and is lost.

Input

The input will consist of one line containing three numbers A, N and K separated by spaces.
A will be between 0 and 1000000000 aggressive.
N will be between 0 and 100 aggressive.
K will be between 1 and 100 aggressive.
All Chambers start off with zero participates initially.

Output

Consists of K numbers on one line followed by a newline. The first number is the number of particles in chamber 0, the second number is the number of particles in Chamber 1 and so on.

Example
Input:3 1 3Output:1 1 0

It is easy to find a rule and use it to solve the problem, rather than simulate the process.

#pragma once#include <vector>#include <string>#include <algorithm>#include <stack>#include <stdio.h>#include <iostream>using namespace std;int NuclearReactors(){int A, N, K;cin>>A>>N>>K;N++;int *tbl = new int[K];int t = A;for (int i = 0; i < K; i++){tbl[i] = t % N;t /= N;}for (int i = 0; i < K; i++){printf("%d ", tbl[i]);}printf("\n");delete [] tbl;return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.