Google Code Jam. Cookie Clicker Alpha

Google Code Jam. Cookie Clicker Alpha
5 1 vote

The Cookie Clicker Alpha is the Problem B of the Google Code Jam 2014 Qualification Round.

Here is my solution for it in C language:


#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define EPS 0.0000001

main() {
    int T, i, c, p, m;
    double C, F, X, Y;
    
    struct Item {
	double y;
	double a;
	double cookies;
    } *H;

    H = (struct Item *) malloc(10000000 * sizeof(struct Item));

    scanf("%d\n", &T);
    for (i = 0; i < T; i++) {
	printf("Case #%d: ", i + 1);
	c = p = m = 0;
	scanf("%lf %lf %lf\n", &C, &F, &X);
	Y = 10000000.0;
	H[p].y = 0.0;
	H[p].a = 2.0;
	H[p].cookies = 0.0;

	while (c <= p) {
	    if (fabs(H[c].cookies - X) < EPS) {
		if (H[c].y < Y) Y = H[c].y;
	    } else if (H[c].y < Y) {
		H[p + 1].y = H[c].y + C/H[c].a;
		H[p + 1].a = H[c].a + F;
		H[p + 1].cookies = 0.0;

		H[p + 2].y = H[c].y + X/H[c].a;
		H[p + 2].a = H[c].a;
		H[p + 2].cookies = X;
		p = p + 2;
	    } 
	    c++;
	}
	printf("%.7lf\n", Y);
    }
}

0 thoughts on “Google Code Jam. Cookie Clicker Alpha

  1. cookie jam cheat tool

    Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the
    message home a bit, but instead of that, this is excellent blog.
    A great read. I will certainly be back.

Leave a Reply

Your email address will not be published. Required fields are marked *