![]() |
This is an interesting example of crowd-sourcing: The class majority got 100%:
| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | |
| A | 1 | 0 | 0 | 0 | 6 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 2 | 56 | 3 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| B | 0 | 0 | 0 | 7 | 2 | 4 | 0 | 0 | 0 | 0 | 0 | 3 | 54 | 2 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| C | 0 | 2 | 5 | 1 | 1 | 1 | 1 | 0 | 44 | 1 | 1 | 0 | 14 | 2 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| D | 1 | 0 | 1 | 1 | 2 | 37 | 4 | 0 | 0 | 0 | 0 | 2 | 18 | 3 | 0 | 3 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| E | 0 | 1 | 0 | 0 | 4 | 48 | 8 | 0 | 0 | 0 | 0 | 0 | 3 | 8 | 0 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| F | 0 | 0 | 1 | 1 | 0 | 3 | 0 | 0 | 3 | 0 | 0 | 1 | 60 | 2 | 1 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| G | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 2 | 1 | 6 | 7 | 9 | 1 | 0 | 1 | 37 | 8 | 0 |
| H | 0 | 0 | 0 | 8 | 1 | 3 | 0 | 0 | 1 | 0 | 0 | 1 | 58 | 1 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| I | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 2 | 1 | 37 | 23 | 0 | 0 | 3 | 1 | 4 | 1 |
| J | 0 | 1 | 0 | 0 | 12 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 54 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| K | 0 | 0 | 0 | 5 | 1 | 3 | 1 | 0 | 1 | 0 | 2 | 1 | 59 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| L | 0 | 0 | 0 | 0 | 2 | 4 | 0 | 0 | 0 | 0 | 1 | 5 | 0 | 2 | 1 | 0 | 3 | 57 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| M | 0 | 1 | 0 | 0 | 11 | 13 | 0 | 0 | 0 | 0 | 0 | 4 | 8 | 30 | 1 | 5 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| N | 24 | 0 | 0 | 0 | 0 | 41 | 0 | 0 | 4 | 0 | 0 | 0 | 3 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
![]() |
Grading. I just went multiple choice on this, with the entries for 4, 6 and 10 counting 1 point each, and the remainder (including the empty 22) counting 0.2 points each.
![]() |
Grading: .5 point for 10's link being 6, .5 point for 6's link being -1, and 1 point for all of the others being identical to part E.
![]() |
121 73 79 186 138 16 68 192 131 198So, the answer is v. One point for w.
16 68 73 79 192 138 186 121 198 131So, the answer is b. One point for l. One point for f.
16 73 79 121 192 138 186 68 198 131So, the answer is g. If you started with index 1 rather than 2, then you would get h, so I gave that full credit too. If you didn't sentinelize, then you'd get either s or t, so I gave half credit for either of those answers.
73 79 121 186 192 138 16 68 198 131So, the answer is r. Half credit for q, as that's what it looks like after the second recursive call (just before the merge).
![]() |
When you condense that into one 10-element vector, you get:
16 68 79 73 121 138 131 198 186 192So, the answer is d. Half credit for e. One point for a.
![]() |
| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | |
| A | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 54 | 3 | 2 | 11 | 0 |
| B | 0 | 58 | 0 | 0 | 0 | 9 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| C | 2 | 3 | 2 | 0 | 1 | 12 | 18 | 12 | 4 | 0 | 0 | 3 | 1 | 0 | 0 | 0 | 1 | 1 | 11 | 3 | 0 | 0 | 0 | 0 | 0 | 1 |
| D | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 2 | 3 | 2 | 18 | 29 | 1 | 1 | 0 | 0 | 0 | 4 | 7 | 1 |
| E | 19 | 0 | 3 | 11 | 5 | 1 | 3 | 0 | 0 | 8 | 4 | 0 | 2 | 4 | 3 | 0 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 2 |
void PQueue::Push(double d)
{
int index, p;
h.push_back(d);
index = h.size()-1;
while (1) {
if (index == 0) return;
p = (index - 1) / 2;
if (h[p] <= h[index]) return;
h[index] = h[p];
h[p] = d;
index = p;
}
}
|
Grading:
![]() |
With 20 elements which can each be 199,999,999, these sums can exceed the maximum value of an integer. For that reason, your sums should be long long's, rather than integers.
N's size: A power set enumeration of N elements is O(2N). You start reaching the 2 second limit in Topcoder at about 222.
Here's an implementation with a main(): (in q5.cpp)
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int RB(int r, int b, vector <int> &N)
{
long long R, B;
int i, j;
R = 0;
for (i = 0; i < N.size(); i++) R += N[i];
if (R != r + b) return 0;
for (i = 0; i < (1 << N.size()); i++) {
R = 0;
B = 0;
for (j = 0; j < N.size(); j++) {
if (i & (1 << j)) {
R += N[j];
} else {
B += N[j];
}
}
if (R == r && B == b) return 1;
}
return 0;
}
main()
{
int r, b, i;
vector <int> N;
cin >> r >> b;
while (cin >> i) N.push_back(i);
printf("%d\n", RB(r, b, N));
exit(0);
}
|
Grading:
![]() |