uva-10112-计算几何

题意:给你一些点,求这些点组成的三角形面积最大,而且三角形内不能包含其他点

#include <iostream>
#include <math.h>
#include<stdio.h>
using namespace std;

struct Node
{
	char c;
	int x;
	int y;
};
void sort(Node nodes[3], int length)
{
	for (int i = 0; i < length; i++)
	{
		for (int j = 1; j < length - i; j++)
		{
			if (nodes[j - 1].c > nodes[j].c)
			{
				Node temp = nodes[j];
				nodes[j] = nodes[j - 1];
				nodes[j - 1] = temp;
			}
		}
	}
}
double area(double x1, double y1, double x2, double y2, double x3, double y3)
{
	double i = (y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1);
	return fabs(i) * 0.5;
}

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (!n)
			return 0;
		Node* nodes = new Node[n];
		Node res[3];
		for (int i = 0; i < n; i++)
		{
			Node node;
			cin >> node.c >> node.x >> node.y;
			nodes[i] = node;
		}
		double maxa = -1;
		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				for (int k = j + 1; k < n; k++)
				{
					double a = area(nodes[i].x, nodes[i].y, nodes[j].x,
							nodes[j].y, nodes[k].x, nodes[k].y);
					if (a <= maxa)
						continue;
					int contain = false;
					for (int t = 0; t < n; t++)
					{
						if(t == i || t == j || t == k)
							continue;
						double s1, s2, s3;
						s1 = area(nodes[t].x, nodes[t].y, nodes[j].x,
								nodes[j].y, nodes[k].x, nodes[k].y);

						s2 = area(nodes[i].x, nodes[i].y, nodes[t].x,
								nodes[t].y, nodes[k].x, nodes[k].y);

						s3 = area(nodes[i].x, nodes[i].y, nodes[j].x,
								nodes[j].y, nodes[t].x, nodes[t].y);
						if ((s1 + s2 + s3) == a)
						{
							contain = true;
							break;
						}
					}
					if (!contain)
					{
						res[0] = nodes[i];
						res[1] = nodes[j];
						res[2] = nodes[k];
						maxa = a;
					}
				}
			}
		}
		sort(res, 3);
		cout << res[0].c << res[1].c << res[2].c << endl;
	}
	return 0;
}

  

时间: 2024-08-08 22:06:59

uva-10112-计算几何的相关文章

uva 1606 (计算几何)

这是我人生中的第一个计算几何题,好好收藏一下. 1.当一个点关于远点对称之后,除了两点之间的连线外,其他的任何直线都会讲两点分成两个部分 2.极角排序 3.线的旋转 4.叉积求 sin #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; class Node { public: int x,y,color; doubl

优质题表(机密版)

转载请注明出处:http://www.cnblogs.com/dashuzhilin/p/4556803.html 思维题: poj 1528 poj 1597 poj 2538 poj 2608 poj 2612 poj 2361 poj 2339 poj 2664 uva 10894 uva 10921   uva 10922   uva 10929 uva 10931   uva 10800   uva 10878 uva 10976   uva 10323   uva 201 poj 2

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

UVA - 11178 - Morley&#39;s Theorem (计算几何~~)

UVA - 11178 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecti

UVA 11178-Morley&#39;s Theorem(计算几何_莫雷定理)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

uva 11178 Morley&amp;#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

uva 11796 Dog Distance (计算几何-点和直线)

C Dog Distance Input Standard Input Output Standard Output Two dogs, Ranga and Banga, are running randomly following two different paths. They both run for T seconds with different speeds. Ranga runs with a constant speed of R m/s, whereas Banga runs

uva 10652 Board Wrapping (计算几何-凸包)

Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the b

uva 11178 Morley&#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

uva 10209 Is This Integration ? (计算几何)

Problem C Is This Integration ? Input: Standard Input Output: Standard Output Time Limit: 3 seconds In the image below you can see a square ABCD, where AB = BC = CD = DA = a. Four arcs are drawn taking the four vertexes A, B, C, Das centers and a as