Cod sursa(job #1083282)

Utilizator Impaler_009Mihai Nitu Impaler_009 Data 15 ianuarie 2014 20:12:23
Problema Dreptunghiuri Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <cmath>

#define e 0.000001

using namespace std;

ifstream fin("dreptunghiuri.in");
ofstream fout("dreptunghiuri.out");

int n,m;
long long total;

bool aprox (double x)
{
    if (x-int(x) < e || int(x)+1-x < e)
        return 1;
    return 0;
}

int main()
{
    fin>>n>>m;

    for (int X=1; X<n; ++X)
        for (int Y=1; Y<m; ++Y)
    {
        int sum = 1;
        for (int x=1; x < X; ++x)
            {
                double delta =  sqrt(4*x*x - 4*X*x + Y*Y);
                if (delta > e)
                {
                    double root = (Y+delta)/2;
                    if (aprox(root) && 0 <= root && root <= Y)
                    {
                        ++sum;
                    }

                    root = (Y-delta)/2;
                    if (aprox(root) && 0 <= root && root <= Y)
                    {
                        ++sum;
                    }
                }

                else if (fabs(delta) < e)
                {
                    if (Y%2==0 && 0 <= Y/2 && Y/2 <= Y)
                        ++sum;
                }
            }
        total += (n-X)*(m-Y)*sum;
    }

    fout<<total;
}