VTRI - Triangles

Tác giả: skyvn97

Ngôn ngữ: C++

#include<cstdio>
struct point {
	int x,y;
	point(){}
	point(const int &_x,const int &_y) {
		x=_x;y=_y;	
	}
	bool operator < (const point &a) const {
		if (x<a.x) return (true);
		if (x>a.x) return (false);
		return (y<a.y);
	}
	bool operator > (const point &a) const {
		return (a<*this);
	}
	bool operator == (const point &a) const {
		return (x==a.x && y==a.y);
	}
};
int x,y,s,r;
point a,b,c;
int main(void) {
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&s);
	r=0;
	for (a.x=0;a.x<=x;a.x++)
		for (a.y=0;a.y<=y;a.y++)
			for (b.x=a.x;b.x<=x;b.x++)
				for (b.y=(a.x==b.x)*(a.y+1);b.y<=y;b.y++)
					for (c.x=b.x;c.x<=x;c.x++) {
						if (a.x==b.x) {
							if (2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y==0) r=r+(c.x>b.x)*(y+1)+(c.x==b.x)*(y-c.y);
							if (-2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y==0) r=r+(c.x>b.x)*(y+1)+(c.x==b.x)*(y-c.y);
						}	
						else {
							if ((2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y)%(b.x-a.x)==0) {
								c.y=(2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y)/(b.x-a.x);
								if (b<c && c.y>=0 && c.y<=y) r++;
							}
							if ((-2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y)%(b.x-a.x)==0) {
								c.y=(-2*s-a.x*b.y+a.y*b.x+c.x*b.y-c.x*a.y)/(b.x-a.x);
								if (b<c && c.y>=0 && c.y<=y) r++;
							}
						}
					}
	printf("%d",r);
	return 0;
}

Download