I have found a solution to this Kattis Problem:
https://open.kattis.com/problems/funnygames
but it uses >?= unix syntax which I need to change to compile in Kattis. I changed them to std::min and std::max respectively, but I'm not getting the right answer (I get Michael everytime).
Original Code:
/* Sample solution to "Funny Games" from NCPC 2005
* Algorithm: essentially continuous DP, keep track of winning intervals
* Author: Per Austrin
*/
#include <cmath>
#include <cassert>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<double, double> pdd;
template <class It, class OIt>
OIt ival_union(It begin, It end, OIt dest) {
sort(begin, end);
while(begin != end) {
*dest = *begin++;
while(begin != end && begin->first < dest->second + 1e-8)
dest->second >?= begin++->second; //Change 1
++dest;
}
return dest;
}
int main(void) {
int n, k;
double x, f[10], maxf;
pdd win[10000], lose;
for (scanf("%d", &n); n--; ) {
scanf("%lf%d", &x, &k);
maxf = lose.second = 0;
for (int i = 0; i < k; ++i)
scanf("%lf", f+i), win[i] = make_pair(1, 1 / f[i]), maxf >?= f[i]; //Change 2
for (int nwin = k, l = 0; x > lose.second; ++l) {
nwin = ival_union(win + l , win + nwin, win + l) - win;
lose.second = (lose.first = win[l].second) / maxf;
if (l < nwin-1) lose.second <?= win[l+1].first; //Change 3
for (int i = 0; i < k; ++i)
win[nwin++] = make_pair(lose.first/f[i], lose.second/f[i]);
}
assert(fabs(x-lose.first) > 1e-6 && fabs(x-lose.second) > 1e-6);
printf("%s\n", x < lose.first ? "Nils" : "Mikael");
}
}
And my 3 changes:
std::max(dest->second, begin++->second); //Change 1
scanf("%lf", f + i), win[i] = make_pair(1, 1 / f[i]), std::max(maxf, f[i]); //Change 2
if (l < nwin - 1) std::min(lose.second, win[l + 1].first); //Change 3
The input is
4
6 2 0.25 0.5
10 2 0.25 0.5
29.29 4 0.3 0.7 0.43 0.54
29.30 4 0.3 0.7 0.43 0.54
The output should be
Mikael
Nils
Nils
Mikael
But after the changes I get
Mikael
Mikael
Mikael
Mikael