Codechef Nuclear Reactors 题解
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.
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 题解的更多相关文章
- Codechef Racing Horses题解
找一个数组中两数之间最小的不同值. 思路: 1 排序 2 后前相减,比較得到最小不同值 三个数甚至很多其它数之间的不同值都是这么求了,时间效率都是O(nlgn) -- 排序使用的时间 原题: http ...
- codechef Arranging Cup-cakes题解
Arranging Cup-cakes Our Chef is catering for a big corporate office party and is busy preparing diff ...
- codechef Turbo Sort 题解
Input t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one ...
- SICP 阅读笔记(二)
Chapter 1: Building Abstractions with Procedures 2015-09-29 016 Preface of this chapter QUOTE: The a ...
- 每日英语:China Poses Challenge for Coal
China's appetite for coal, once seemingly unlimited, is starting to wane, and the effects are rippli ...
- SPOJ QTREE6 Query on a tree VI 树链剖分
题意: 给出一棵含有\(n(1 \leq n \leq 10^5)\)个节点的树,每个顶点只有两种颜色:黑色和白色. 一开始所有的点都是黑色,下面有两种共\(m(1 \leq n \leq 10^5) ...
- CodeChef November Challenge 2013 部分题解
http://www.codechef.com/NOV13 还在比...我先放一部分题解吧... Uncle Johny 排序一遍 struct node{ int val; int pos; }a[ ...
- Codechef Not a Triangle题解
找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...
- codechef February Challenge 2018 简要题解
比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...
随机推荐
- MVC in Javascript
MVC in Javascript From http://www.cnblogs.com/tugenhua0707/p/5156179.html 原博的比我详细 我是以自己的惯用的方式实现了一下 M ...
- JDK常见问题 环境变量配置
"javac不是内部命令或外部命令" Windows7 安装"jdk-6u26-windows-x64.exe"后,常提示"javac不是内部命令或外 ...
- secedit
secedit /export /cfg mytemplate.inf /log mylog.txt http://www.oracle-base.com/dba/script.php?categor ...
- C#dll版本号默认生成规则
原文:C#dll版本号默认生成规则 1.版本号自动生成方法 只需把 AssemblyInfo.cs文件中的[assembly: AssemblyVersion("1.0.0.0") ...
- Ubuntu 12.04下安装ibus中文输入法
这是最完整的安装方法: ibu是一个框架,可以支持多种输入法,像是pinyin,五笔等. 1,安装ibus框架 终端输入以下命令: sudo apt-get install ibus ibus-clu ...
- Spring、使用注解方式装配对象(@Resource、@Autowired)
使用手工注解方式有两种方式@Resource.@Autowired 首先,引入注解所使用的Jar包 :common-annotations.jar 然后在beans.xml中加入命名空间空间 xml ...
- HTML5实现坦克大战(一)
Tank 字段 x:坦克的中心点的横坐标 y:坦克的中心点的纵坐标 dir:坦克的前进的方向 spped:坦克的速度 color:坦克的颜色,用于区分种类不同的坦克 bullet:坦克的子弹 为a ...
- jquery 获取当前元素的索引值
$("#lisa > li").mouseover(function(){ alert($("#lisa > li").length); alert ...
- 制作与使用静态链接库(.lib)文件
(一)制作.lib文件 (1)打开vs,选择“新建项目”,选择“Visual C++“,选择”Win32 控制台应用程序“. (2)点击”确定“,点击”下一步“,设置如下 (3)点击”完成“,然后就可 ...
- VARIANT类型
VARIANT的结构可以参考头文件VC98\Include\OAIDL.H中关于结构体tagVARIANT的定义.struct tagVARIANT { union { ...