Java

UVa 102: Ecological Bin Packing

UVa 102: Ecological Bin Packing

We’re back to doing another simple UVa Online Judge problem, and this time we take on problem 102, Ecological Bin Packing. In the problem we are asked to solve a bin packing problem about recycling glass. It can be easily solved with brute force, but requires careful coding. Enough yapping, let’s take a look at the problem description.

Interpretation

We have three bins, each of which contains some number of bottles. There are three types of bottles; brown, green and clear, denoted by “B”, “G” and “C”, respectively. We are given how many  bottles of each type are in each bin. Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 1 comment
UVa 530: Binomial Showdown

UVa 530: Binomial Showdown

Problem 530 at the UVa Online Judge, also known as Binomial Showdown, asks us to compute the number of ways one can choose elements out of elements, not taking order into account. The problem is a classical one ( choose , anyone?), but with a twist. The input numbers are big, and we need to be really careful not to overflow integers in our intermediate computations. We discover a formula that has smaller intermediate values than the direct formula, and with one more small observation, we’re done. Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 3 comments
UVa 10268: 498-bis

UVa 10268: 498-bis

Problem 10268 at the UVa Online Judge, 498′, asks us to evaluate the derivative of a polynomial. It is, like the name suggests, a version of problem 498, which we’ve already covered here. We solved problem 498 with code reuse in mind. We created a Polynomial class which we can extend to solve this problem. Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 0 comments
UVa 10127: Ones

UVa 10127: Ones

Problem 10127 at UVa Online Judge, Ones, is a neat little problem. We are given an integer and are asked to find its smallest multiple that consists only of ones. More specifically, we are asked for the number of ones in that multiple.

Interpretation

We are given an integer that is neither divisible by nor . We have to find the smallest multiple of that consists entirely of ones. For example, when , is the smallest multiple of that consists only of ones. For this problem, we only need the digit count of that multiple, which in the case of is (because  has digits). Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 4 comments
UVa 294: Divisors

UVa 294: Divisors

In UVa 294, Divisors, we are asked to find the number with the maximum number of divisors in a given range. Counting number of divisors is a classic problem, and there exists a fast and simple way to do it. We start off with a straight-forward, but slow, implementation and progressively optimize it until it’s fast enough. We don’t stop there, though, but we end with a much faster implementation by noticing that divisor count is related to prime factorization.

Read the problem description here or here. Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 8 comments
UVa 100: The 3n + 1 problem

UVa 100: The 3n + 1 problem

The problem (or UVa 100) is the first problem at UVa’s online judge. The problems there are not in any particular order, as can be seen from this first problem which is far from being the easiest (but also very far from being the hardest). You can read the problem statement here or here. Continue reading →

Posted by Bjarki Ágúst in UVa Online Judge, 11 comments