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. Carmine

    Hey, Ruxandra! Oscilloskope (www.oscilloskope.com) is a new player on the market. Oscilloskope monitors the whole web’s universe, social media (including REAL Facebook monitoring), forums, blogs, Reddit, Youtube and much more. Track and monitor your product, your name as an entrepreneur and see the conversations happening around you or your product. Cheers!

    http://allin1panel.com/blog/social-media-marketing-tips-guide/

Leave a Reply

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