Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

5555555 WA得不能再WA了, 高人好心帮忙看看。。。谢啦!

Posted by qywyh_scut at 2006-04-28 23:31:22 on Problem 2826
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

struct point 
{
	double x;
	double y;
};

double area(double a, double b, double c)
{
	double rtn;
	double s = (a + b + c) / 2;
	rtn = sqrt(s * (s - a) * (s - b) * (s - c));
	return rtn;
}
int main() 
{
	double PI = 2 * asin(1);
	point p1, p2, p3, p4;
	point p0, p_tmp;
	double k;
	double a, b, c;
	double ans;
	double cita;
	int caseTime;
	cin >> caseTime;
	while (caseTime-- != 0)
	{
		cin >> p1.x >> p1.y;
		cin >> p2.x >> p2.y;
		cin >> p3.x >> p3.y;
		cin >> p4.x >> p4.y;
		if (p1.y < p2.y)
		{
			swap(p1, p2);
		}
		if (p3.y < p4.y)
		{
			swap(p3, p4);
		}
		if (p1.y == p2.y || p3.y == p4.y)
		{
			cout << "0.00" << endl;
			continue;
		}

		if (p1.x == p2.x && p3.x == p4.x)
		{
			cout << "0.00" << endl;
			continue;
		}

		if (p1.x == p2.x || p3.x == p4.x)
		{
			if (p3.x == p4.x)
			{
				swap(p1, p3);
				swap(p2, p4);
			}
			p0.y = (p4.y - p3.y) * (p2.x - p3.x) / (p4.x - p3.x) + p3.y;
			if (p0.y < p2.y && p0.y < p4.y)
			{
				cout << "0.00" << endl;
			}
			else
			{
				if (p1.y > p3.y)
				{
					ans = fabs(p3.x-p1.x) * fabs(p3.y-p0.y) / 2;
				}
				else
				{
					ans = fabs((p1.y - p3.y) * (p4.x - p3.x) / (p4.y - p3.y) + p3.x - p1.x) *
						  fabs(p1.y-p0.y) / 2;
				}
				ans *= 100;
				//	ans = ceil(ans);
				ans += 0.5;
				ans = int(ans) / 100;
				cout << setiosflags(ios::fixed) << setprecision(2) << ans << endl;
			}
			continue;
		}

		
		p0.x = ((p2.y - p1.y) / (p2.x - p1.x) * p1.x - p1.y - (p4.y - p3.y) / (p4.x - p3.x) * p3.x + p3.y)
			   / ((p2.y - p1.y) / (p2.x - p1.x) - (p4.y - p3.y) / (p4.x - p3.x));

		p0.y = ((p2.y - p1.y) / (p2.x - p1.x) * (p0.x - p1.x) + p1.y);

		if (p0.y < p2.y && p0.y < p4.y)
		{
			cout << "0.00" << endl;
			continue;
		}

		if (p1.y >= p3.y)
		{
			swap(p1, p3);
			swap(p2, p4);
		}
		a = sqrt((p1.x - p0.x) * (p1.x - p0.x) + (p1.y - p0.y) * (p1.y - p0.y));

		p_tmp.x =  (p4.x - p3.x) / (p4.y - p3.y) * (p1.y - p3.y) + p3.x;
		b =sqrt((p_tmp.x - p0.x) * (p_tmp.x - p0.x) + (p1.y - p0.y) * (p1.y - p0.y));

		c = fabs((p_tmp.x - p1.x));

		ans = area(a, b, c);

		ans *= 100;
		ans += 0.5;
	//	ans = ceil(ans);
		ans = int(ans) / 100;
		cout << setiosflags(ios::fixed) << setprecision(2) << ans << endl;

	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator