[gym101047K Training with Phuket's larvae] 给定N条边求能组成三角形的最小面积
来源:互联网 发布:金融数据挖掘 马超群 编辑:程序博客网 时间:2024/06/01 07:32
[gym101047K Training with Phuket’s larvae] 给定N条边求能组成三角形的最小面积
题目链接:[gym101047K Training with Phuket’s larvae]
题意描述:给定N条边,
解题思路:
首先,对所有的边进行排序,然后遍历两条边a, b,(假设
因为三角形两边边长固定的情况下,第三条边尽可能短,或者第三条边尽可能长都会使得面积变小。换句话说,就是使得这三角形尽可能瘪….
#include <queue>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)#define fst first#define snd secondtypedef __int64 LL;typedef pair<int, int> PII;const double eps = 1e-8;const int MAXN = 2000 + 5;const int INF = 0x3f3f3f3f;int T, N, M;double A[MAXN];inline int sgn (double x, double y) { if (fabs (x - y) == 0) return 0; return x < y ? -1 : 1;}inline double getArea (double a, double b, double c) { double x = (a + b + c) / 2.0; return sqrt (x * (x - a) * (x - b) * (x - c) );}int main() {#ifndef ONLINE_JUDGE FIN; // FOUT;#endif // ONLINE_JUDGE double a, b, c, res; scanf ("%d", &T); while (T --) { scanf ("%d", &N); for (int i = 0; i < N; i++) { scanf ("%lf", &A[i]); } sort (A, A + N); res = (double) INF; for (int i = 0; i < N; i++) { a = A[i]; for (int j = i + 1; j < N; j++) { b = A[j]; int low = upper_bound (A + j + 1, A + N, b - a) - A; int high = lower_bound (A + j + 1, A + N, a + b) - A - 1; if (low < N) { c = A[low]; if (sgn (a + b, c) <= 0 || sgn (a + c, b) <= 0 || sgn (b + c, a) <= 0) continue; res = min (res, getArea (a, b, c) ); } if (high > low) { c = A[high]; if (sgn (a + b, c) <= 0 || sgn (a + c, b) <= 0 || sgn (b + c, a) <= 0) continue; res = min (res, getArea (a, b, c) ); } } } if (sgn (res, (double) INF) == 0) { printf ("-1\n"); } else { cout << fixed << setprecision (8) << res << "\n"; } } return 0;}
拓展一下:
在挑战竞赛上17页有一个求最大周长的题目。作者只是提到了一个Nlog(N)的做法让读者思考。
我的做法:首先对边长排序。然后呢,要使得周长最大,主要取相邻的三条满足条件的边。这样的复杂度就是Nlog(N)。
0 0
- [gym101047K Training with Phuket's larvae] 给定N条边求能组成三角形的最小面积
- 给出三点求组成的三角形面积
- 给定三角形的三边长,求三角形的面积
- HDU 5448 Marisa’s Cake(n个点中任意点组成的多边形面积之和)
- 打印由0-n组成的三角形
- 三个点使组成的三角形面积最大
- poj 1948 dp(组成面积最大的三角形)
- [ACM] HDU 5135 Little Zu Chongzhi's Triangles (一堆木棍组成三角形最大面积)
- 给定一个N位的数,返回由这N个数组成的比原来的数大数中的最小的数
- 给定一个N位的数,返回由这N个数组成的比原来的数大数中的最小的数
- UVA 10347 || Medians(中线组成的三角形面积是原三角形的3/4
- P122 第三章 10题 三角形的面积及三边是否能组成三角形的判断
- 区间DP 最大面积最小的三角形划分
- HDU_4242_Rancher's Gift(三角形面积)
- SPOJ3931(N个点形成三角形的最大面积)
- n行数字组成的数字三角形详解
- 给定数m,求由n位数的组成m的数列(m>=n>0)
- 求给定M个数组合构成N的最小倍数
- 矩阵旋转算法提高75%运算
- 02.vi编辑器的使用
- POJ 2955 Brackets 区间dp入门题
- 暑期工作日志-Day5
- 大数操作
- [gym101047K Training with Phuket's larvae] 给定N条边求能组成三角形的最小面积
- 七层网络模型与四层网络模型以及每层网络协议
- 小码哥哥 FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- Ajax实现瀑布流图片加载
- 最长非递减子序列的应用
- ubuntu安装搜狗输入法出现两个图标和两个输入框的解决方式
- 树状数组求区间和
- H264学习(四)帧内预测
- 面向对象_创建对象做了哪些事情?