Codechef Nuclear Reactors 题解
2014-05-04 07:01
363 查看
There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. The particles keep collecting in the chamber 0. However if at any time, there are more than N particles 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 particles in the current chamber will be be destroyed and same continues till no chamber has number of particles greater than N. Given K,N and the total number of
particles bombarded (A), find the final distribution of particles in the K chambers. Particles 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.
The input will consist of one line containing three numbers A,N and K separated by spaces.
A will be between 0 and 1000000000 inclusive.
N will be between 0 and 100 inclusive.
K will be between 1 and 100 inclusive.
All chambers start off with zero particles initially.
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.
找出规律就好办,利用规律解决问题,而不是模拟过程。
to the immediate next chamber(if current chamber is 0, then to chamber number 1), and all the particles in the current chamber will be be destroyed and same continues till no chamber has number of particles greater than N. Given K,N and the total number of
particles bombarded (A), find the final distribution of particles in the K chambers. Particles 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 inclusive.
N will be between 0 and 100 inclusive.
K will be between 1 and 100 inclusive.
All chambers start off with zero particles 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 3 Output: 1 1 0
找出规律就好办,利用规律解决问题,而不是模拟过程。
#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; }
相关文章推荐
- Codechef Nuclear Reactors 题解
- 4299: Codechef FRBSUM
- [BZOJ4260]Codechef REBXOR(Trie)
- Codechef TAPAIR
- BZOJ 4260 Codechef REBXOR 01Trie
- codechef_Home » Compete » January Challenge 2013 » The Minimum Number Of Moves
- Maximum number, GCD condition (CodeChef)
- CodeChef:Consecutive Snakes(三分)
- codechef Enormous Input Test 快速读入数据 fread
- codechef Correctness of Knight Move题解
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
- codechef Turbo Sort 题解
- 4260: Codechef REBXOR
- CodeChef PrimeDST【点分治】【FFT】
- CodeChef "Chef and Churus" 分块+树状数组
- CodeChef:Minimum SubArray(线段树最值)
- codechef SHORT
- codechef February Challenge 2016
- CodeChef CBAL
- [BZOJ4408&&BZOJ4299][FJOI2016 && Codechef]神秘数&&FRBSUM(主席树)