Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Pipe Fitters

121.c

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

#define MAX(a,b) ((a) > (b) ? (a) : (b))

int
skew(float a, float b)
{
	int height;
	int tot;

	if (b<1) {
		return 0;
	} else {
		height = 1 + (b-1)/(sqrt(3)/2);
	}

	tot = (height-height/2)*(int)a + height/2*(int)(a-0.5);

	return tot;
}

int
main(void)
{
	float a, b;

	while(1) {
		int grid;
		int skew1, skew2;

		if (scanf("%f %f", &a, &b)!=2) {
			break;
		}
		grid = (int)a * (int)b;
		skew1 = skew(a, b);
		skew2 = skew(b, a);
		if ((skew1>grid) || (skew2>grid)) {
			printf("%d skew\n", MAX(skew1,skew2));
		} else {
			printf("%d grid\n", grid);
		}
	}

	exit(0);
}