diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 3024f62..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/boxes-per-hour/config.yaml b/boxes-per-hour/config.yaml new file mode 100644 index 0000000..38db350 --- /dev/null +++ b/boxes-per-hour/config.yaml @@ -0,0 +1,14 @@ +# Set the problem type to interactive +type: interactive + +# Specify the interactor source file +interactor: interactor.cc + +# Time and memory limits still apply to the contestant's solution +time: 2s +memory: 512m + +# The subtasks section works the same way +subtasks: + - score: 100 + n_cases: 10 # Looks for 1.in, 2.in, ... 5.in \ No newline at end of file diff --git a/boxes-per-hour/interactor.cc b/boxes-per-hour/interactor.cc new file mode 100644 index 0000000..1f6b6ff --- /dev/null +++ b/boxes-per-hour/interactor.cc @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include + +#include "testlib.h" + +int main(int argc, char* argv[]) { + // Initialize the interactor. + // inf = test case input (.in), visible to contestant + // ouf = contestant's output stream + // ans = secret answer file (.ans), hidden from contestant + registerInteraction(argc, argv); + + // Read secret information from .ans file + // The .ans file should now contain the best_queries value first, then the + // permutation. + + int x, y, z; + double dec_rat; + x = inf.readInt(); + y = inf.readInt(); + z = inf.readInt(); + dec_rat = inf.readDouble(); + double curr_rate = 1.0000; + println(x); + println(y); + println(z); + println(dec_rat); + + // std::vector v(100); + double best_boxes = ans.readDouble(); + // best_boxes = 100.000; + // for (int i = 0; i < 100; ++i) v[i] = inf.readChar(); + /* + +#if 0 + for (int i = 0; i < 100; ++i, curr_rate *= dec_rat) { + println('G'); + } + quitp(1.0f, "Ratio: 1.000"); + return 0; +#endif + */ + + // Send public n to contestant + std::vector c(3, 'x'); + std::vector cnt(3, 0.00); + for (int i = 0; i < 100; ++i, curr_rate *= dec_rat) { + std::string str = inf.readString(); + char col = str[0]; + println(col); + std::string action_type; + int num; + action_type = ouf.readWord(); + if (action_type == "DISCARD") { + continue; + // you literally dont do anything + } else { + num = ouf.readInt(); + } + if (action_type == "EMPTY") { + cnt[num] = 0; + c[num] = 'x'; + continue; + } + if (action_type == "PLACE") { + if (cnt[num] == 0 || c[num] == col) { + c[num] = col; + cnt[num] += curr_rate; + } else { + // cooked, its in the wrong one + quitf(_wa, "-1"); + // quitp(1.0f, "Ratio: 1.000"); + } + } else { + quitf(_wa, "-1"); + // quitp(1.0f, "Ratio: 1.000"); + } + } + /* + double truescore = cnt[1] + cnt[2]; + double s = truescore / best_boxes / 100.0; + quitp(s, "Ratio: %.4f", s); + */ + + /* + return 0; + double truescore = cnt[1] + cnt[2]; + if (truescore < best_boxes * 0.5) { + double score_ratio = 0.000; + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } else { + double score_ratio = (truescore - best_boxes * 0.5) / (best_boxes * 0.5); + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } + */ + double truescore = cnt[1] + cnt[2]; + if (truescore > best_boxes) { + double score_ratio = 1.000; + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } else { + if (truescore < best_boxes * 0.5) { + double score_ratio = 0.000; + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } else { + double score_ratio = (truescore - best_boxes * 0.5) / (best_boxes * 0.5); + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } + } + + /* + if (truescore < best_boxes * 0.5) { + double score_ratio = 0.000; + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } else { + double score_ratio = (truescore - best_boxes * 0.5) / (best_boxes * 0.5); + quitp(score_ratio, "Ratio: %.4f", score_ratio); + } + */ + + // double score_ratio = (double)(cnt[0] + cnt[1]) / (double)best_boxes; + // quitp(score_ratio, "Ratio: %.4f"); + return 0; +} diff --git a/boxes-per-hour/statement.txt b/boxes-per-hour/statement.txt new file mode 100644 index 0000000..719e29d --- /dev/null +++ b/boxes-per-hour/statement.txt @@ -0,0 +1,68 @@ +Problem: 100 Boxes Per Day + At work, you sort 100 boxes per day. Each box has one of three colours: red, blue, or green. The boxes come +through a slot, so you cannot see what boxes have yet to come. You want to take as many boxes home as possible, +but you only have two bins to store them in. The boxes that are placed inside bins are also more valuable than later boxes. +Specifically: the value of a box is equal to 1 * decay_rate ^ (i), where i is the order of the box that you recieved. +Unfortunately, although the bins are not limited in capacity, yo umust cannot have two boxes of different colours be in the same bin. + + Thankfully, a coworker told you the distribution of the box colours but forgot to specify the colours. All you have +are three integers that add up to 100. When you receive a box, you can do three things. First, you can choose to +empty either bin you have, discarding all boxes inside it. After that, you can place the box into a bin that is either +empty or contains only boxes of the specified colour. Alternatively, you can simply discard the current box. +You suspect that these boxes are valuable, so you want to keep as many as possible. Today, you start with two empty boxes. +Find a way to maximize the total value of the boxes you collect. + +Interaction: + +For the day you work, you will receive a line with three integers: A, B, and C, indicating that there are A boxes +of some colour, B boxes of another colour, and C of the remaining colour. It is guaranteed that 0 <= A, B, C <= 100 +and A+B+C = 100. Then, you will receive the decay_rate, a floating point real number less than 1 but greater than 0. + +Then, you will start your hour of work. You will be given a line with a single character, one of “R”, “G”, or “B”, +indicating the colour of the current box. Then you may empty either bin, with “EMPTY 1” or “EMPTY 2”. You may +empty either bin as many times as you’d like. Then, either output “PLACE x” where x is the bin to place the box +into, or output “DISCARD” to discard the current box. In any case, after printing each line, remember to output a +newline character and flush the output. + +If at any point you output an invalid instruction or put two boxes of different colours in one bin, you will receive +a line with a single integer, -1. At this point, your program should terminate, and you will receive a score of 0. + +Furthermore, the test cases are not random in any way. They are pre-generated to cover the worst possible cases. + +Producing an algorithm that always generates optimal solutions is very difficult, so your solution only needs to be "good enough". The higher value of the boxes you collected, the higher your score. +Your final score will be calculated as the average of 100 * clamp((your_value-base_line)/(best_value-base_line), 0, 1) across all test cases. + +Time limit: 2 seconds + +Memory Limit: 1024 MB + + +Example Input: +5 2 3 +G +G +B +B +G +G +R +G +B +R +Example Output: +PLACE 2 +PLACE 1 +EMPTY 1 +PLACE 1 +EMPTY 2 +EMPTY 1 +PLACE 2 +DISCARD +DISCARD +PLACE 1 +DISCARD +PLACE 2 +PLACE 1 + +Note: +The sample interaction shows a valid exchange, as A + B + C = 10. It will not appear in any of the test cases. \ No newline at end of file diff --git a/boxes-per-hour/testdata/1.ans b/boxes-per-hour/testdata/1.ans new file mode 100644 index 0000000..400122e --- /dev/null +++ b/boxes-per-hour/testdata/1.ans @@ -0,0 +1 @@ +1.5 \ No newline at end of file diff --git a/boxes-per-hour/testdata/1.in b/boxes-per-hour/testdata/1.in new file mode 100644 index 0000000..149ee7c --- /dev/null +++ b/boxes-per-hour/testdata/1.in @@ -0,0 +1,101 @@ +32 24 44 0.45 +R +G +R +B +R +B +G +R +R +B +B +R +G +G +G +G +R +G +G +R +R +B +G +G +R +B +B +G +R +R +R +B +G +G +R +G +G +R +G +G +R +B +R +R +G +B +R +G +G +R +B +B +R +G +G +G +R +R +G +G +B +G +R +G +G +R +B +G +G +B +G +R +B +B +R +B +B +G +B +G +G +G +B +G +R +R +B +G +G +G +R +G +G +R +B +G +B +G +R +G diff --git a/boxes-per-hour/testdata/10.ans b/boxes-per-hour/testdata/10.ans new file mode 100644 index 0000000..b44fe09 --- /dev/null +++ b/boxes-per-hour/testdata/10.ans @@ -0,0 +1 @@ +65 \ No newline at end of file diff --git a/boxes-per-hour/testdata/10.in b/boxes-per-hour/testdata/10.in new file mode 100644 index 0000000..16ab9ed --- /dev/null +++ b/boxes-per-hour/testdata/10.in @@ -0,0 +1,101 @@ +19 12 69 1 +G +G +G +B +B +G +G +G +R +G +G +G +G +G +G +G +B +B +G +G +G +B +B +G +R +G +G +G +G +B +G +G +G +G +G +R +G +G +G +G +G +G +G +R +G +G +G +G +G +G +G +R +G +G +B +G +R +B +G +G +G +G +B +B +G +R +G +G +B +G +G +B +G +R +B +R +R +G +G +G +G +R +B +B +G +G +B +G +G +G +B +G +G +R +G +G +G +G +G +B diff --git a/boxes-per-hour/testdata/2.ans b/boxes-per-hour/testdata/2.ans new file mode 100644 index 0000000..430c4f0 --- /dev/null +++ b/boxes-per-hour/testdata/2.ans @@ -0,0 +1 @@ +1.67 \ No newline at end of file diff --git a/boxes-per-hour/testdata/2.in b/boxes-per-hour/testdata/2.in new file mode 100644 index 0000000..a7e7976 --- /dev/null +++ b/boxes-per-hour/testdata/2.in @@ -0,0 +1,101 @@ +57 15 28 0.67 +B +R +B +B +B +R +G +B +B +B +B +B +B +G +B +B +R +R +B +B +B +R +B +B +B +R +R +B +B +B +B +B +G +B +R +R +B +G +B +B +R +G +R +B +G +B +B +B +G +R +R +B +B +R +R +B +G +B +R +B +R +R +G +G +B +B +R +B +G +B +B +B +B +B +R +B +R +R +B +B +B +B +B +B +G +R +G +B +R +B +R +G +B +B +G +B +R +R +B +R diff --git a/boxes-per-hour/testdata/3.ans b/boxes-per-hour/testdata/3.ans new file mode 100644 index 0000000..c793025 --- /dev/null +++ b/boxes-per-hour/testdata/3.ans @@ -0,0 +1 @@ +7 \ No newline at end of file diff --git a/boxes-per-hour/testdata/3.in b/boxes-per-hour/testdata/3.in new file mode 100644 index 0000000..c2b1a4c --- /dev/null +++ b/boxes-per-hour/testdata/3.in @@ -0,0 +1,101 @@ +32 33 35 0.9 +R +G +B +R +R +R +B +G +R +R +R +R +G +G +R +G +B +G +B +R +B +B +R +R +B +G +G +B +G +B +G +B +B +G +R +R +B +G +B +G +B +G +G +G +B +R +B +R +G +B +B +G +R +R +G +G +B +R +G +B +B +R +B +R +G +R +G +R +B +G +G +R +R +G +B +B +R +G +B +R +G +G +B +B +R +R +B +B +G +G +B +R +G +R +R +R +G +R +B +R diff --git a/boxes-per-hour/testdata/4.ans b/boxes-per-hour/testdata/4.ans new file mode 100644 index 0000000..b44fe09 --- /dev/null +++ b/boxes-per-hour/testdata/4.ans @@ -0,0 +1 @@ +65 \ No newline at end of file diff --git a/boxes-per-hour/testdata/4.in b/boxes-per-hour/testdata/4.in new file mode 100644 index 0000000..2319595 --- /dev/null +++ b/boxes-per-hour/testdata/4.in @@ -0,0 +1,101 @@ +10 37 53 1 +G +B +R +B +B +R +R +B +B +B +B +R +G +G +R +R +R +R +B +R +R +B +G +B +R +B +G +R +B +B +B +R +B +B +R +B +R +B +B +R +R +B +B +G +B +R +B +R +R +B +R +R +R +R +B +R +G +R +B +R +R +R +R +R +B +R +R +R +R +B +B +R +B +R +B +R +R +R +B +R +R +R +R +R +R +B +R +B +R +B +R +R +B +R +B +G +R +R +G +G diff --git a/boxes-per-hour/testdata/5.ans b/boxes-per-hour/testdata/5.ans new file mode 100644 index 0000000..2b82dfe --- /dev/null +++ b/boxes-per-hour/testdata/5.ans @@ -0,0 +1 @@ +60 \ No newline at end of file diff --git a/boxes-per-hour/testdata/5.in b/boxes-per-hour/testdata/5.in new file mode 100644 index 0000000..3ca24fa --- /dev/null +++ b/boxes-per-hour/testdata/5.in @@ -0,0 +1,101 @@ +27 42 31 1 +B +R +B +R +B +G +G +B +R +B +R +B +B +G +B +R +B +B +B +G +G +R +B +R +R +G +G +R +R +G +R +R +B +R +R +B +B +G +G +R +B +B +R +B +B +B +B +R +R +G +G +G +G +B +B +B +R +R +G +R +G +G +B +G +B +B +G +B +B +R +B +R +R +B +G +B +B +R +G +G +R +B +B +B +R +G +B +R +G +B +G +G +B +B +B +G +R +B +R +R diff --git a/boxes-per-hour/testdata/6.ans b/boxes-per-hour/testdata/6.ans new file mode 100644 index 0000000..400122e --- /dev/null +++ b/boxes-per-hour/testdata/6.ans @@ -0,0 +1 @@ +1.5 \ No newline at end of file diff --git a/boxes-per-hour/testdata/6.in b/boxes-per-hour/testdata/6.in new file mode 100644 index 0000000..6cba4d4 --- /dev/null +++ b/boxes-per-hour/testdata/6.in @@ -0,0 +1,101 @@ +5 64 31 0.5 +B +B +B +B +B +G +G +B +R +R +B +B +B +B +G +G +B +B +B +G +G +G +B +G +B +G +B +B +B +G +B +B +B +B +B +G +B +B +G +B +B +B +G +B +B +G +B +B +G +G +G +G +B +G +B +B +G +B +B +B +B +B +G +B +G +B +B +B +B +G +B +G +B +R +G +G +B +B +B +R +G +B +B +B +B +B +B +G +G +G +B +B +G +B +B +R +B +B +B +B diff --git a/boxes-per-hour/testdata/7.ans b/boxes-per-hour/testdata/7.ans new file mode 100644 index 0000000..d8263ee --- /dev/null +++ b/boxes-per-hour/testdata/7.ans @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/boxes-per-hour/testdata/7.in b/boxes-per-hour/testdata/7.in new file mode 100644 index 0000000..7089d09 --- /dev/null +++ b/boxes-per-hour/testdata/7.in @@ -0,0 +1,101 @@ +44 22 34 0.7 +G +B +R +B +G +R +R +B +B +G +R +G +B +R +R +G +R +B +G +R +R +B +G +B +B +R +R +B +R +B +B +G +B +G +R +G +R +G +R +G +R +B +R +R +G +B +G +G +R +G +G +G +G +R +R +G +G +R +R +B +R +R +R +B +R +G +G +G +R +R +G +R +R +B +R +R +R +R +G +B +G +G +R +R +R +G +R +B +B +B +R +G +R +R +R +G +G +G +G +R diff --git a/boxes-per-hour/testdata/8.ans b/boxes-per-hour/testdata/8.ans new file mode 100644 index 0000000..4684374 --- /dev/null +++ b/boxes-per-hour/testdata/8.ans @@ -0,0 +1 @@ +1.8 \ No newline at end of file diff --git a/boxes-per-hour/testdata/8.in b/boxes-per-hour/testdata/8.in new file mode 100644 index 0000000..f159dde --- /dev/null +++ b/boxes-per-hour/testdata/8.in @@ -0,0 +1,101 @@ +44 17 39 0.8 +R +B +R +B +B +G +R +R +B +B +R +R +R +B +R +R +R +R +R +R +B +B +B +B +B +B +B +R +B +R +G +R +B +R +B +B +G +B +B +B +B +G +G +G +R +G +R +G +R +B +R +R +G +R +R +B +B +G +B +B +B +R +B +R +B +B +B +R +G +R +B +B +R +G +R +R +B +B +G +B +B +R +G +R +R +B +R +B +B +B +G +G +G +R +B +R +R +B +B +R diff --git a/boxes-per-hour/testdata/9.ans b/boxes-per-hour/testdata/9.ans new file mode 100644 index 0000000..e3f1e9b --- /dev/null +++ b/boxes-per-hour/testdata/9.ans @@ -0,0 +1 @@ +80 \ No newline at end of file diff --git a/boxes-per-hour/testdata/9.in b/boxes-per-hour/testdata/9.in new file mode 100644 index 0000000..5e22a06 --- /dev/null +++ b/boxes-per-hour/testdata/9.in @@ -0,0 +1,101 @@ +20 32 48 1 +G +G +R +G +R +R +G +G +B +G +R +G +R +B +G +G +R +G +G +R +G +G +G +R +G +B +G +B +G +B +R +G +B +B +G +B +R +R +B +R +B +R +R +G +G +G +B +G +G +R +B +G +G +G +R +R +R +B +R +G +R +G +R +G +B +R +R +R +G +G +R +G +B +B +G +B +R +G +G +G +R +R +B +G +R +G +R +R +B +G +R +G +G +G +G +G +G +B +G +G