-
Notifications
You must be signed in to change notification settings - Fork 0
/
11005.cpp
54 lines (41 loc) · 884 Bytes
/
11005.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<stdio.h>
/* Cheapest Base - 11005 */
int converte(long n, int base,int cost[]){
int n_cost=0;
do
{
n_cost+=cost[n%base];
n/=base;
}while(n!=0);
return n_cost;
}
main(){
int i,j,c,Case=0,base,queries,cost[36],n_cost[36];
long n;
scanf("%d",&c);
for(;c>0;c--)
{
Case++;
for(i=0;i<36;i++)
scanf("%d",&cost[i]);
scanf("%d",&queries);
printf("Case %d:\n",Case);
for(i=1;i<=queries;i++)
{
scanf("%ld",&n);
for(base=2;base<=36;base++)
n_cost[base-2]=converte(n,base,cost);
printf("Cheapest base(s) for number %ld:",n);
base=n_cost[0];
for(j=1;j<35;j++)
if(n_cost[j]<base)
base=n_cost[j];
for(j=0;j<36;j++)
if(n_cost[j]==base)
printf(" %d",j+2);
printf("\n");
}
if(c!=1)
printf("\n");
}
}