POJ1569 Myacm Triangles
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
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
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的更多相关文章
- ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)
Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
- [ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)
Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...
- acdream.Triangles(数学推导)
Triangles Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Stat ...
- UVA 12651 Triangles
You will be given N points on a circle. You must write a program to determine how many distinctequil ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
- 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 ...
随机推荐
- 解决pycharm添加第三方包失败
今天想用pycharm打开图像,但是import scipy的时候报错了,报错内容如下: from scipy.misc import imread Traceback (most recent ca ...
- scrapy python2升级python3遇到的坑
换成Python3首先pycharm先执行: 然后看代码自己所需要的第三方库都要重新装 然后执行代码: 遇到这样的错如下: SyntaxError: invalid syntax 先检查print 所 ...
- ERROR in Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (64)
该问题说的是当前环境不支持node-sass,网上说了一下是要安装node 7一下版本才支持. 这里改使用less-loader,及less
- 羽翼metasploit第一,二季学习笔记
-----------------第一季-------------------- 启动Metasploit:msfconsole 升级和更新:./msfupdate 直接退出:exit 退回上一级:q ...
- vue 和react的区别
1.数据是不是可变的 react整体是函数式的思想,把组件设计成纯组件,状态和逻辑通过参数传入,所以在react中,是单向数据流,推崇结合immutable来实现数据不可变. react在setSta ...
- numpy.where() 用法详解
numpy.where (condition[, x, y]) numpy.where() 有两种用法: 1. np.where(condition, x, y) 满足条件(condition),输出 ...
- JAVA学习笔记系列1-Java版本介绍
JavaSE(Java Standard Edition):标准版,定位在个人计算机上的应用(桌面应用).因为一般都是Windows系统,因此Java的这个发展并不好. JavaEE(Java Ent ...
- C#添加文字水印
使用的是iTextSharp添加PDF水印,由于是接口动态生成PDF,所以采用的是全部是内存流的形式,而且水印是平铺是.iTextSharp版本是5.5 /// <summary> /// ...
- Add和AddRange的使用
Add 是每次将单个元素添加到集合里面 AddRange可以一次性添加多个元素到集合里面 AddRange例子: public static int ExecuteCommand(st ...
- c程序的期望
对于C语言,我认为是我们计算机专业必须掌握的,如果C语言都不能掌握好,我认为在以后的学习中也不会学的有多好,所以,我们要把C语言尽量掌握好,也是在今后的学习中打好基础,多看书,多写一些程序运行,做一些 ...