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); }