All pastes #41380 Raw Edit

Stuff

public text v1 · immutable
#41380 ·published 2006-02-13 05:16 UTC
rendered paste body
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

class FindTriangle
{
	public:
		double largestArea(vector <string>points)
		{	
			vector<string> v;
			v.reserve(3);		
			double max = 0.0;
			for ( int i = 0; i < points.size(); i++)
			{
				v.push_back(points[i]);
				for ( int k = 0; k < points.size(); k++)
				{
					if ( k == i ) continue;
					//cout << points[k] << endl;
					v.push_back(points[k]);
					for ( int m = 0; m < points.size(); m++)
					{	
						//cout << "color i:" << color(points[i]) << "color k:" << color(points[k]) << "color m:" << color(points[m]) << endl; 
						if ( (m == i) || ( m == k) ) continue;
						if ( (color(points[m]) == color(points[i])) && ( color(points[k]) == color(points[i])) )
							v.push_back(points[m]);
						else if ( (color(points[m]) != color(points[i]) ) && (color(points[k]) != color(points[i]))&& (color(points[m]) != color(points[k])) )
							v.push_back(points[m]);	
						else
							continue;
						double t;	
					//	cout << v[0] << endl;
					//cout << v[1] << endl;
					//cout << v[2] << endl;
						if ( (t=area(v)) > max) 
							max = t;
						//	cout << "max: " << max << endl;
						v.pop_back();
					}
					v.pop_back();
				}
				v.pop_back();		
			}
			if ( max <= 1.0e-9) return 0.0;
			return max;
		}
		double area(vector<string> v)
		{
			int del[3];
			int index = -1;
			int i = 0;
			
			while ( (index = v[0].find(" ", index+1)) != string::npos) {
			//	cout << index << endl;
				del[i++] = index;
			}
			int x1 = atoi(v[0].substr(del[0]+1, del[1]-1).c_str());
			int y1 = atoi(v[0].substr(del[1]+1, del[2]-1).c_str());
			int z1 = atoi(v[0].substr(del[2]+1).c_str());
			
			i = 0;
			index = -1;
			while ( (index = v[1].find(" ", index+1)) != string ::npos)
				del[i++] = index;	 
			
			int x2 = atoi(v[1].substr(del[0]+1, del[1]-1).c_str());
			int y2 = atoi(v[1].substr(del[1]+1, del[2]-1).c_str());
			int z2 = atoi(v[1].substr(del[2]+1).c_str());
			
			i = 0;
			index = -1;
			while ( (index = v[2].find(" ", index+1)) != string ::npos)
				del[i++] = index;	 
			int x3 = atoi(v[2].substr(del[0]+1, del[1]-1).c_str());
			int y3 = atoi(v[2].substr(del[1]+1, del[2]-1).c_str());
			int z3 = atoi(v[2].substr(del[2]+1).c_str());
			
			long double a = pow((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1), 0.5);
			long double b = pow((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) + (z3-z1)*(z3-z1),0.5);
			long double c = pow((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) + (z3-z2)*(z3-z2),0.5);					
//			 cout << "a " << a << "b " << b << " c " << c << endl;
			long double ar = 0.25*pow((a + b +c)*(b + c - a)*(c+a-b)*(a+b-c), 0.5);
			//cout << "area calc: " << ar << endl;
			return (double)ar;
		}
		char color(string s)
		{
			return s.c_str()[0];
		}
	
};