When printing text on paper we need ink. But not every character needs the same amount of ink to print: letters such as ’W’, ’M’ and ’8’ are more expensive than thinner letters as ’i’, ’c’ and ’1’. In this problem we will evaluate the cost of printing numbers in several bases.

As you know, numbers can be expressed in several different bases. Well known bases are binary (base 2; digits 0 and 1), decimal (base 10; digits 0 to 9) and hexadecimal (base 16; digits 0 to 9 and letters A to F). For the general base n we will use the first n characters of the string “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”,which means the highest base in this problem is 36. The lowest base is of course 2.

Every character from this string has an associated cost, represented by an integer value between 1 and 128. The cost to print a number in a certain base is the sum of the costs of all characters needed to represent that number. For the numbers given in the input, you will have to calculate the cheapest base(s) to represent this number in. Numbers in any base are printed without leading zeros.

Input

The input has less than 25 test cases. The first line of input file denotes this number of test cases. The description of every test case is given below:

The first 4 lines of every case contain 9 integers each: the costs of the 36 characters in the order given above. Then follows the number of queries on a line by itself. Every query appears on a line by itself and is formed by a number between 0 and 2000000000 in decimal format.

Output

For every case in the input, print one line ‘Case X:’, without the quotes, where X is the case number starting from 1.

For every query within a case print one line ‘Cheapest base(s) for number Y :’ followed by the cheapest base(s) in increasing order, separated by one space. Y is the query in decimal format. Print a blank line between cases.

The numbers in the second sample output are actually all in one line just like the first sample output. Due to lack of horizontal space they are shown broken in two lines.

Sample Input

2

10 8 12 13 15 13 13 16 9

11 18 24 21 23 23 23 13 15

17 33 21 23 27 26 27 19 4

22 18 30 30 24 16 26 21 21

5

98329921

12345

800348

14

873645

1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1

4

0

1

10

100

Sample Output

Case 1:

Cheapest base(s) for number 98329921: 24

Cheapest base(s) for number 12345: 13 31

Cheapest base(s) for number 800348: 31

Cheapest base(s) for number 14: 13

Cheapest base(s) for number 873645: 22

Case 2:

Cheapest base(s) for number 0: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

Cheapest base(s) for number 1: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

Cheapest base(s) for number 10: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36

Cheapest base(s) for number 100: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2526 27 28 29 30 31 32 33 34 35 36

问题链接:UVA11005 Cheapest Base

问题简述:(略)

问题分析

关键是读懂题意!不解释。

程序说明:(略)

题记:把功能封装到函数是个好主意。

参考链接:(略)

AC的C++语言程序如下:

/* UVA11005 Cheapest Base */#include <bits/stdc++.h>using namespace std;const int N = 36;
int costs[N];
int v[N], vcnt;int cost(int n, int m)
{int rtn = 0;if(n) {while(n) {rtn += costs[n % m];n /= m;}}return rtn;
}void calc(int n)
{int min = INT_MAX, t;vcnt = 0;for(int i=2; i<=N; i++) {t = cost(n, i);if(t == min)v[vcnt++] = i;else if(t < min){min = t;vcnt = 0;v[vcnt++] = i;}}
}int main()
{int t, caseno = 0, q, n;scanf("%d", &t);while(t--) {for(int i=0; i<N; i++)scanf("%d", &costs[i]);if(++caseno > 1)putchar('\n');printf("Case %d:\n", caseno);scanf("%d", &q);while(q--) {scanf("%d", &n);calc(n);printf("Cheapest base(s) for number %d:", n);for(int i=0; i<vcnt; i++)printf(" %d", v[i]);putchar('\n');}}return 0;
}

UVA11005 Cheapest Base【数学】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  3. Excel函数词典(483个函数说明 Excel函数公式Excel小技巧

    Excel函数词典(483个函数说明 Excel函数公式Excel小技巧 函数 类别 属性 新函数 说明 语法 BETADIST 兼容性函数 被替换 BETA.DIST 返回累积 beta 概率密度函 ...

  4. 【202105小白训练营】-day02 java基础

    后端开发工程师 市场最具竞争力,专业技能,随着软件技术成熟,时代发展,软件工程师学习核心重点发生变化 1)早期程序员20年前,学习重点五笔字型(练习打字120),网络建网,语言入门c,vb 2)早期程 ...

  5. 高薪聘请2021/2022届本/硕/博数学、物理、统计、计算机、软件等专业 1、量化软件开发工程师(本科211以上)base北上杭深关键词:c++、python、java软件开发

    高薪聘请2021/2022届本/硕/博 数学.物理.统计.计算机.软件等专业 1.量化软件开发工程师 (本科211以上)base北上杭深 关键词:c++.python.java软件开发 年40-70万 ...

  6. Python学习笔记17:标准库之数学相关(math包,random包)

    前面几节看得真心累.如今先来点简单easy理解的内容. 一 math包 math包主要处理数学相关的运算. 常数 math.e   # 自然常数e math.pi  # 圆周率pi 运算函数 math ...

  7. Numpy入门教程:04. 数学函数

    背景 什么是 NumPy 呢? NumPy 这个词来源于两个单词 – Numerical和Python.其是一个功能强大的 Python 库,可以帮助程序员轻松地进行数值计算,通常应用于以下场景: 执 ...

  8. 程序员的数学3 线性代数_在编程大佬眼中,线性代数到底是什么样的?

    线性代数是什么? 在大学数学学科中,线性代数是最为抽象的一门课,从初等数学到线性代数的思维跨度比微积分和概率统计要大得多.很多人学过以后一直停留在知其然不知 其所以然的阶段,若干年之后接触图形编程或机 ...

  9. python数学库的使用方法_浅谈numpy库的常用基本操作方法

    NumPy数组的维数称为秩(rank),一维数组的秩为1,二维数组的秩为2,以此类推.在NumPy中,每一个线性的数组称为是一个轴(axes),秩其实是描述轴的数量.比如说,二维数组相当于是一个一维数 ...

最新文章

  1. hdu5246超级赛亚ACMer
  2. Android phone xp 华为3x,3000mAh大电池 华为荣耀3X续航能力实测
  3. matlab生成有向网络,matlab ode45和矩阵生成有向网络图
  4. 【yarn】INFO ipc.Client Retrying connect to server xxx 8032 Already tried 0 time(s)
  5. 多阶段决策求最优解----动态规划(Dynamic Programming)
  6. CentOS7 Docker 安装 PHP,Mysql,phpmyadmin
  7. 【ubuntu操作系统入门】Ubuntu常用命令大全二
  8. 《SpringBoot实战》笔记1
  9. cookie的工作原理
  10. 七牛云 PHP SDK服务器鉴权失败!参数解释
  11. 大理古城“悟空、八戒”与人互殴 警方:四人被行拘
  12. 华科计院数据库课程笔记
  13. 1425 加工生产调度
  14. 云创办公智慧企业丨企业的下一个前沿阵地
  15. c语言税务信息申报系统,四川税务网上申报系统
  16. Python数据类型练习题
  17. python+opencv-12 黑帽和礼帽运算
  18. uboot中ftd命令
  19. 第七届开源操作系统年度技术会议(OS2ATC)盛大开幕,从编译器到软件定义卫星精彩议题大曝光
  20. 主要的CMS(内容管理系统)提供商

热门文章

  1. mqtt发布json数据_mqtt应用于进程间通信
  2. ArcGIS Pro 简明教程(2)基础操作和简单制图
  3. pymysql之常见数据库操作
  4. 资深开发者告诉你“页游转手游”应注意的五大点
  5. DXUT框架剖析(5)
  6. 红黑树的删除_从红黑树的本质出发,彻底理解红黑树!
  7. python图像增强_使用Python进行图像增强
  8. java做h5小游戏服务端_神藏西游H5游戏源码服务端+客户端+搭建教程
  9. Kylin Cube构建优化
  10. 洛谷P3879 [TJOI2010] 阅读理解 哈希Hash解法