Description


There has been considerable archeological work on the ancient Myacm culture. Many artifacts have been found in what have been called power fields: a fairly small area, less than 100 meters square where there are from four to fifteen tall monuments with crystals on top. Such an area is mapped out above. Most of the artifacts discovered have come from inside a triangular area between just three of the monuments, now called the power triangle. After considerable analysis archeologists agree how this triangle is selected from all the triangles with three monuments as vertices: it is the triangle with the largest possible area that does not contain any other monuments inside the triangle or on an edge of the triangle. Each field contains only one such triangle.

Archeological teams are continuing to find more power fields. They would like to automate the task of locating the power triangles in power fields. Write a program that takes the positions of the monuments in any number of power fields as input and determines the power triangle for each power field.

A useful formula: the area of a triangle with vertices (x1, y1), (x2, y2), and (x3, y3) is the absolute value of

0.5 * [(y3 - y1)(x2 - x1) - (y2 - y1)(x3 - x1)].

Input

For each power field there are several lines of data. The first line is the number of monuments: at least 4, and at most 15. For each monument there is a data line that starts with a one character label for the monument and is followed by the coordinates of the monument, which are nonnegative integers less than 100. The first label is A, and the next is B, and so on.

There is at least one such power field described. The end of input is indicated by a 0 for the number of monuments. The first sample data below corresponds to the diagram in the problem.

Output

For each power field there is one line of output. It contains the three labels of the vertices of the power triangle, listed in increasing alphabetical order, with no spaces.

Sample Input

6
A 1 0
B 4 0
C 0 3
D 1 3
E 4 4
F 0 6
4
A 0 0
B 1 0
C 99 0
D 99 99
0

Sample Output

BEF
BCD

『题解』

题目大意是给一些点,这些点可以构成很多三角形。要在所有内部不含其它点的三角形中找出面积最大的。

枚举三角形的三个顶点a,b,c。主要问题在于如何判断三角形内没有其它的点。事实上,若点p在三角形abc内,则叉积(a - b) ^ (p - b),(b - c) ^ (p - c),(c - a) ^ (p - a)是同号的。此方法同样适用与判断点是否在凸多边形内。

三角形abc面积的求法题目给出了,用叉积|(a - b) ^ (c - b) / 2|。在满足条件的三角形中找面积最大的即可。

枚举三角形的三个顶点,对于每个三角形还要枚举判断内部是否包含其它点,因而时间复杂度为O(n ^ 4)。

『C++』

 #include <iostream>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
using namespace std; struct Vector {
double x, y;
Vector() :x(), y() {}
Vector(double xx, double yy) :
x(xx), y(yy) {}
}pts[]; int n; double operator ^(const Vector &v1, const Vector &v2) {
return v1.x * v2.y - v1.y * v2.x;
} Vector operator -(const Vector &v1, const Vector &v2) {
return Vector(v1.x - v2.x, v1.y - v2.y);
} double Area(const Vector &A, const Vector &B, const Vector &C) {
return fabs(0.5 * ((B - A) ^ (C - A)));
} bool InTriangle(const Vector &A, const Vector &B,
const Vector &C, const Vector &P) {
double d1 = (A - B) ^ (P - B);
double d2 = (B - C) ^ (P - C);
double d3 = (C - A) ^ (P - A); if ((d1 >= && d2 >= && d3 >= ) ||
(d1 <= && d2 <= && d3 <= ))
return true;
return false;
} bool Check(int pn1, int pn2, int pn3) {
for (int i = ; i < n; i++) {
if (i == pn1 || i == pn2 || i == pn3)
continue;
if (InTriangle(pts[pn1], pts[pn2], pts[pn3], pts[i]))
return false;
}
return true;
} int main()
{
while (scanf_s("%d", &n) == && n) {
if (n == )break; double ans = ;
int num[] = {}; for (int i = ; i < n; i++) {
char c;
cin >> c >> pts[i].x >> pts[i].y;
} for(int i = ; i < n; i++)
for(int j = i + ; j < n; j++)
for(int k = j+; k < n; k++)
if (Check(i, j, k)) {
double area = Area(pts[i], pts[j], pts[k]);
if (ans < area) {
ans = area;
num[] = i;
num[] = j;
num[] = k;
}
} printf("%c%c%c\n", 'A' + num[], 'A' + num[], 'A' + num[]);
} //system("pause");
return ;
}

POJ1569 Myacm Triangles的更多相关文章

  1. ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)

    Description   Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  4. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  5. [ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)

    Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...

  6. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  7. UVA 12651 Triangles

    You will be given N points on a circle. You must write a program to determine how many distinctequil ...

  8. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  9. Codeforces Round #309 (Div. 1) C. Love Triangles dfs

    C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...

随机推荐

  1. 颜色(color)透明

    颜色写法: 1.英文单词 backgroud-color:red: 2. #fff background-color:#fff; 3.#fefefe background-color:fefefe; ...

  2. 2、使用Angular-CLI初始化Angular项目(踩过的深坑!!!)

    1.step1:建一个放项目的文件夹,打开cmd,或vs code的终端,找到文件夹根目录 2.step2:初始化脚手架 初始化命令: ng new 项目名称 --skip-install 注意:-- ...

  3. learning makefile multiple target

  4. ThinkPHP5模型操作中的自动时间戳总结

    ThinkPHP5中提供了非常优秀的自动时间戳功能.使用起来非常方便. 但是官网手册中的说明还是不是很详尽,因此整理再次,以方便后续使用时查阅. 一.一般情况下的自动填充create_time,upd ...

  5. 查看shell 命令 路径

    type [root@web01 ~]# type mount mount is /bin/mount which [root@web01 ~]# type ifconfig ifconfig is ...

  6. css样式问题解决

    1.关于滚动条 (1)布局后由于写了 overflow-y: scroll; 在内容还没有超出就出现了滚动条. 我的解决方法是直接去掉了滚动条: .class::-webkit-scrollbar { ...

  7. AFNetworking 3.0简单数据请求get&post

    /** *get请求方法 */ - (void)AFNGetUrl { AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; ...

  8. python day 25--正则表达式

    一.字符组 1.[0-9]表示匹配0-9中的数字 2.[a-z]表示匹配a-z之间的字母 3.[A-Z]表示匹配大写的字母 4.[0-9a-zA-Z]匹配所有字母数字 二.元字符 1.\d 匹配任意数 ...

  9. 剑指Offer 16. 合并两个排序的链表 (链表)

    题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 题目地址 https://www.nowcoder.com/practice/d8b6b4358 ...

  10. [LeetCode&Python] Problem 844. Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...