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

#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;
}

  

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

  1. UVa 11796 计算几何

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVa 11178计算几何 模板题

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  3. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  4. UVA 12304 - 2D Geometry 110 in 1! - [平面几何基础题大集合][计算几何模板]

    题目链接:https://cn.vjudge.net/problem/UVA-12304 题意: 作为题目大合集,有以下一些要求: ①给出三角形三个点,求三角形外接圆,求外接圆的圆心和半径. ②给出三 ...

  5. UVa 1331 - Minimax Triangulation(区间DP + 计算几何)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

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

    Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states tha ...

  7. Uva 10652 Board Wrapping(计算几何之凸包+点旋转)

    题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...

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

    Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...

  9. UVA 10652 Board Wrapping 计算几何

    多边形凸包.. .. Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...

  10. 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)

    题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...

随机推荐

  1. Microsoft - Union Two Sorted List with Distinct Value

    Union Two Sorted List with Distinct Value Given X = { 10, 12, 16, 20 } &  Y = {12, 18, 20, 22} W ...

  2. B树就想到这个

    比如要查找60 先在根结点中查,根结点里面有 17  35这2个关键字, 60 > 35,则从右边开始查找 p3指针开始查找 ,  到了第二层的最右边的那个结点开始查找 , 里面有  65  8 ...

  3. sql server merge into 与update 批量更新1 百万测试数据的性能比较

    1. 1百万的测试数据的生成 declare @index int;  begin  set @index=0;  while @index<1000000  begin  insert int ...

  4. web 分享代码片段

    <div class="bshare-custom icon-medium-plus"><a title="分享到QQ空间" class=&q ...

  5. 【VB.NET】——若水归海

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/successA/article/details/34496209 看完台湾微软特约资深讲师的VB.N ...

  6. npx 知识点

    npx 介绍:https://segmentfault.com/a/1190000010149499

  7. node 知识点

    问:局部安装如何使用npm run命令? 答:如果已局部安装了babel-cli(babel-cli自带babel-node命令),package.json文件配置如下: "scripts& ...

  8. SpringMVC Controller 介绍及常用注解

    摘要: @Controller.@RequestMapping(属性:value.params .method.headers).@PathVariable.@RequestParam.@Cookie ...

  9. php常量PHP_EOL

    换行符 unix系列用 \n windows系列用 \r\n mac用 \r PHP中可以用PHP_EOL来替代,以提高代码的源代码级可移植性 如: <?php echo PHP_EOL; // ...

  10. 线性模型的fit,predict

    线性模型的fit其实一个进行学习的过程,根据数据和标签进行学习:predict则是基于fit之后形成的模型,来决定指定的数据对应于标签(y_train_5)的值. 下面的是手写字母判断是否为“5” s ...