Cod sursa(job #2590332)

Utilizator NicolaalexandraNicola Alexandra Mihaela Nicolaalexandra Data 27 martie 2020 19:19:57
Problema Dreptunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("dreptunghiuri.in");
ofstream fout ("dreptunghiuri.out");
int n,m,i,j,k;
double get_dist (double x, double y, double x2, double y2){
    return (x - x2) * (x - x2) + (y - y2) * (y - y2);
}
int main (){

    fin>>n>>m;

    long long sol = 0;
    for (i=2;i<=n;i++)
        for (j=2;j<=m;j++){

            /// fixez un punct de pe latime
            int latime = min (i,j), lungime = max (i,j);
            double xc = 1.0*(latime-1)/2.0, yc = 1.0*(lungime-1)/2.0;

            int cnt = 1;
            for (int k=1;k<latime-1;k++){

                double dist = get_dist (k,0,xc,yc);
                double val = sqrt (dist - xc * xc);
                if (val + yc == (int)(val+yc) ){
                    /// inseamna ca e un punct ok
                    cnt += 2;
                    if (i == j) /// patrat
                        cnt--;
                }

            }

            sol += 1LL * cnt * (n-i+1) * (m-j+1);

        }

    fout<<sol;

    return 0;
}