Cod sursa(job #1173922)

Utilizator enedumitruene dumitru enedumitru Data 21 aprilie 2014 11:03:35
Problema Dreptunghiuri Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include<fstream>
#include<iostream>
#include<cmath>
using namespace std;
ifstream f("dreptunghiuri.in"); ofstream g("dreptunghiuri.out");
int m,n,w,h,a,b,r,x,y,p;
int nr;
int main()
{	f>>m>>n; 
	for(h=1;h<m;h++)
		for(w=1;w<n;w++)
		{	p=(m-h)*(n-w);
			nr+=p;
			//cout<<"* "<<h<<' '<<w<<" dim "<<(m-h)*(n-w)<<'\n';
			for(a=1;a<=h;a++)
			{	b=h-a;
				r=w*w-4*a*b;
				if(r>0)
				{	y=(int)sqrt((double)r);
					if(y*y==r)
					{	x=w-y;
						if(!(x&1) && x>0) 
							{	//cout<<"**** "<<h<<' '<<w<<" a="<<a<<" c="<<x/2<<'\n';
								nr+=p;
							}
						x=w+y;
						if(!(x&1) && x/2<w) 
							{	//cout<<"**** "<<h<<' '<<w<<" a="<<a<<" c="<<x/2<<'\n';
								nr+=p;
							}
					}
				}
				if(!r && !(w&1)) 
					{	//cout<<"**** "<<h<<' '<<w<<" a="<<a<<" c="<<x/2<<'\n';
								nr+=p;
					}
			}
		}
	g<<nr<<'\n';	
	g.close(); return 0;
}