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); } }
相关文章推荐
- eclipse 打包三方jar包
- 栈与队列
- Java中HashMap遍历的两种方式
- 静态内部类和内部类的区别
- hql相关
- node 模块 fs-extra
- js对象排序&&倒序
- DNS 原理入门
- 关于js判断鼠标移入元素的方向——上下左右
- LeetCode-Self Crossing
- php中fsockopen模仿post与get详解
- 硬件设计规范
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) D 双向dp
- SSM框架 +MYSQL数据库 配置事务控制的方法和注意点
- update maven之后jre被改成1.5的问题
- Android 热修复 - AndFix 使用心得
- 文字 jquery文字动画插件LetterFX 7种不同变换效果
- linux 下查看机器是cpu是几核的(转)
- Spring MVC中,事务是否可以加在Controller层
- go tool proof