Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions boxes-per-hour/config.yaml
Original file line number Diff line number Diff line change
@@ -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
126 changes: 126 additions & 0 deletions boxes-per-hour/interactor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#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<char> 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<char> c(3, 'x');
std::vector<double> 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;
}
68 changes: 68 additions & 0 deletions boxes-per-hour/statement.txt
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions boxes-per-hour/testdata/1.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.5
101 changes: 101 additions & 0 deletions boxes-per-hour/testdata/1.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions boxes-per-hour/testdata/10.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
65
Loading