POJ 2954 Triangle (Pick定理)

http://poj.org/problem?id=2954


完整代码:

/*0ms,356KB*/

#include<cstdio>
#include<cstdlib>
#include<cmath>

int x[4], y[4];

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

double s()
{
	double ret = 0.0;
	for (int i = 0; i < 3; ++i) ret += x[i] * y[i + 1] - y[i] * x[i + 1];
	return fabs(ret) / 2.0;
}

int main()
{
	double A;
	int B;
	while (scanf("%d%d%d%d%d%d", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2]), x[0] || y[0] || x[1] || y[1] || x[2] || y[2])
	{
		x[3] = x[0], y[3] = y[0];
		B = 0;
		for (int i = 0; i < 3; i++) B += gcd(abs(x[i] - x[i + 1]), abs(y[i] - y[i + 1]));
		printf("%d\n", (int)s() - B / 2 + 1);
	}
	return 0;
}

你可能感兴趣的:(C++,ACM,poj,Pick定理)