[go: up one dir, main page]

Skip to content

Commit

Permalink
Added P11005.
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseD committed Dec 26, 2017
1 parent 6bd9a87 commit 1d94c2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
40 changes: 40 additions & 0 deletions P11005.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
int prices[36];

LL getPrice(int N, int base) {
LL ret = 0;
if(N == 0)
return prices[0];
while(N > 0) {
ret += prices[N % base];
N/=base;
}
return ret;
}

int main() {
LL priceForBase[37];

FORCAS {
if(cas != 0)
cout << endl;
cout << "Case " << cas+1 << ":" << endl;

FORI(36)
cin >> prices[i];
GI(Q);
FORI(Q) {
GI(N);
cout << "Cheapest base(s) for number " << N << ":";
LL minPrice = priceForBase[2] = getPrice(N, 2);
for(int base = 3; base <= 36; ++base) {
priceForBase[base] = getPrice(N, base);
minPrice = MIN(minPrice, priceForBase[base]);
}
for(int base = 2; base <= 36; ++base) {
if(minPrice == priceForBase[base])
cout << " " << base;
}
cout << endl;
}
}
}
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,9 @@ Area of triangle using semiperimeter (side lengths).
P11000.cpp: Bee
Trivial.

P11005.cpp: Cheapest Base
Trivial.

P11040.cpp: Add bricks in the wall
Trivial.

Expand Down

0 comments on commit 1d94c2f

Please sign in to comment.