UVA - 11277 Cyclic Polygons(二分)
题意:已知圆的内接多边形的各个边长,求多边形的面积。
分析:
1、因为是圆的内接多边形,将多边形的每个顶点与圆心相连,多边形的面积就等于被分隔成的各三角形之和。
2、根据海伦公式,任意一个三角形的面积为:double p = (2 * r + a[i]) / 2,S = sqrt(p * (p - r) * (p - r) * (p - a[i])),a[i]为多边形某条边的长度,由此可以表示出多边形的面积。
3、对于任意一个三角形,设其为半径的两条边的夹角为α,则sin(α/2) = (a[i] / 2) / r,所以α = 2 * asin(a[i] / 2 / r)。
4、注意asin()函数的计算结果是弧度值,所以所有三角形的夹角和应与2
比较大小。
5、二分确定半径大小,并通过夹角和验证。
(1)二分设置一个上限
(2)judge()函数判断对于每一个三角形是否符合两边之和大于第三边,如果2 * r小于或等于a[i],说明半径过小,所以应当l = mid + eps。
(3)如果judge()函数成立,将所有三角形的夹角和与2
比较,若小于,说明半径过长,因此r = mid - eps;若大于,说明半径过短,因此l = mid + eps;若相等,则符合要求。
6、注意浮点数比较大小。
7、若n<=2,则不构成多边形,输出0.000。
8、若最长边大于或等于其他所有边之和,则构不成多边形,输出0.000,即ma 大于或等于 sum - ma。
9、因为计算过程中会损失精度,结果最好加上eps。
10、本题虽然结果保留小数点后三位,但是为保证精度,eps设置为1e-15,而半径的查找上限设置为1e15。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
double a[MAXN];
int n;
int dcmp(double a, double b){
if(fabs(a - b) < eps) return ;
return a < b ? - : ;
}
bool judge(double r){
for(int i = ; i < n; ++i){
if(dcmp( * r, a[i]) != ) return false;
}
return true;
}
int Equal(double r){
double ans = ;
for(int i = ; i < n; ++i){
ans += * asin(a[i] / / r);
}
return dcmp(ans, * pi);
}
double get_R(double l, double r){
int tmp = ;
while(tmp--){
double mid = l + (r - l) / ;
if(!judge(mid)) l = mid + eps;
else{
int w = Equal(mid);
if(w == ) l = mid + eps;
else if(w == -) r = mid - eps;
else return mid;
}
}
return l;
}
double solve(){
double r = get_R(, 1e15);
double sum = 0.0;
for(int i = ; i < n; ++i){
double p = ( * r + a[i]) / ;
sum += sqrt(p * (p - r) * (p - r) * (p - a[i]));
}
return sum;
}
int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
double ma = ;
double sum = ;
for(int i = ; i < n; ++i){
scanf("%lf", &a[i]);
sum += a[i];
if(dcmp(a[i], ma) == ) ma = a[i];
}
if(n <= || dcmp( * ma, sum) != -){
printf("0.000\n");
continue;
}
printf("%.3lf\n", solve() + eps);
}
return ;
}
UVA - 11277 Cyclic Polygons(二分)的更多相关文章
- uva 1335 - Beijing Guards(二分)
题目链接:uva 1335 - Beijing Guards 题目大意:有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个相邻的人拥有同一种礼物, ...
- UVA - 11478 - Halum(二分+差分约束系统)
Problem UVA - 11478 - Halum Time Limit: 3000 mSec Problem Description You are given a directed grap ...
- UVa 714 Copying Books - 二分答案
求使最大值最小,可以想到二分答案. 然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难). Code /** * UVa * Problem#12627 * Accepted * T ...
- hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)Total ...
- UVA 10341 Solve It 二分
题目大意:给6个系数,问是否存在X使得等式成立 思路:二分.... #include <stdio.h> #include <math.h> #define EEE 2.718 ...
- UVa 11107 (后缀数组 二分) Life Forms
利用height值对后缀进行分组的方法很常用,好吧,那就先记下了. 题意: 给出n个字符串,求一个长度最大的字符串使得它在超过一半的字符串中出现. 多解的话,按字典序输出全部解. 分析: 在所有输入的 ...
- UVA 714 Copying Books 二分
题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...
- UVa 1644 (筛素数 + 二分) Prime Gap
题意: 给出一个整数n,如果n是素数输出0,否则输出它后一个素数与前一个素数的差值. 分析: 首先用筛法把前十万个素数都筛出来,然后放到数组里.用二分找到不大于n的最大的素数的下标,如果这个素数等于n ...
- UVa LA 4254 - Processor 二分,贪心 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
随机推荐
- 跳蚤[BZOJ4310](后缀数组+二分答案传判定)
不知道后缀数组的请退回去! 题面: 题目描述 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究.首先,他会把串分成不超过 k 个子串,然后对于每个子串 S,他会从S ...
- Day3-M-Cable master POJ1064
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...
- 洛谷 P1094 纪念品分类
刚开始看到这题就确定这题最好先要排序 第一个想法是排好序后先让第一个和从倒数第一个开始相加和如果就 <= w,那么用n除以2或者再加一得出答案,然后发现随便 当w = 110 n = 5序列 ...
- 102、Java中String类之相等判断(忽略大小写)
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- vmware fusion 进入 BIOS
要进入bios有三种方法:1.>启动的时候按F2即可进入bios进行一些启动盘等选项的操作.但是,启动的时候很难第一时间按F2成功进入bios, 2.>修改vmware 进入bios之前的 ...
- rapid-generator JAVA代码生成器
有感于马上要做个比较大的业务系统,想到那无止境的增删改查.粘贴复制,顿时脑后升起一阵凉风.于是想到个找或者写一个Java代码的生成器,这样在正常开发进度下,也能余下更多的时间去做些别的事情. 闲话少说 ...
- JS操作小记
this.Phenomenon.forEach(element => { if (element.value3 == this.prvphe) { this.Reason1 = element. ...
- POJ 3274:Gold Balanced Lineup 做了两个小时的哈希
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13540 Accepted: ...
- QT5安装
Windows+Qt5.3.1+VS2013安装教程 https://blog.csdn.net/two_ye/article/details/96109876 (已成功)windows下,VS201 ...
- ubuntu---NVIDIA驱动 + CUDA 安装完可能会遇见的问题
如果稍不注意:系统内核.GCC.下载的版本不对应.安装过程中选项选择不正确,在NVIDIA驱动 + CUDA 安装完后可能会遇见一些问题. 一.登陆不进桌面 可能的操作: (1)nivida驱动安装完 ...