您的位置:首页 > 其它

UVA 10112 Myacm Triangles

2016-07-13 14:49 483 查看

UVA-10112

题意:给n个点,求其中不包含其他点的面积最大的三角形。

解题思路:暴力枚举三个点算面积,并判断其他点会不会在里面。判断点在不在里面的方法有好几个,因为题目给了坐标算面积的公式,所以这里就用面积法。如果p在abc内的话有 Sabc = Sabp + Sacp +Sbcp。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct node{
int x,y;
char c;
} s[20];
int n;
int a1,a2,a3;
double area(int i, int j, int k){
double S = 0.5*((s[k].y-s[i].y)*(s[j].x-s[i].x)-(s[j].y-s[i].y)*(s[k].x-s[i].x));
if (S<0) S=-S;
return S;
}
int main () {
freopen("xx.in","r",stdin);
while (scanf("%d\n",&n) && n) {
for (int i = 1; i <= n; i++)
scanf("%c%d%d\n",&s[i].c,&s[i].x,&s[i].y);
double maxs=0.0,S=0;
for (int i = 1; i <= n; i++)
for (int j = i+1; j <= n; j++)
for (int k = j+1; k <=n; k++) {
S = area(i,j,k);
if (S > maxs){
bool tag=false;
for (int l = 1; l <= n; l++){
if (l != i && l != j && l != k && S == area(i,j,l)+ area(i,k,l)+ area(j,k,l)){
tag=true;
break;
}
}
if (!tag) {
maxs=S;

a1=i;a2=j;a3=k;
}
}
}
printf("%c%c%c\n",s[a1].c,s[a2].c,s[a3].c);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: