Cod sursa(job #344489)

Utilizator CezarMocanCezar Mocan CezarMocan Data 30 august 2009 13:22:21
Problema Dreptunghiuri Scor 70
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.93 kb
#include <cstdio>
#include <math.h>

using namespace std;

int n, m, w, h, l1, l2, L1, L2, sol;
int a, b, c, nr;
double delta;
double x1, x2;

int main() {
	freopen("dreptunghiuri.in", "r", stdin);
	freopen("dreptunghiuri.out", "w", stdout);

	scanf("%d%d", &n, &m);
//	n--; m--;
	for (w = 2; w <= n; w++)
		for (h = 2; h <= m; h++) {
			nr = 0;
			for (l1 = 0; l1 < h - 1; l1++) {
				l2 = h - l1 - 1;
				a = 2;
				b = -2 * (w - 1);
				c = 2 * l1 * l2;
				delta = b * b - 4 * a * c;
				if (delta < 0)
					continue;
				delta = sqrt(delta);

				x1 = (-b + delta) / 4.0;
				x2 = (-b - delta) / 4.0;

//				fprintf(stderr, "%d %d %d  %lf   %lf %lf\n", a, b, c, delta * delta, x1, x2);

				if (x1 == (int)x1 && x1 > 0 && x1 < w)
					nr++;
				if (x2 != x1 && x2 == (int)x2 && x2 > 0 && x2 < w)
					nr++;
			}
//			fprintf(stderr, "%d %d  %d\n", w, h, nr);
			sol += nr * (n - w + 1) * (m - h + 1);
		}

	printf("%d\n", sol);
		

	return 0;
}