hdu 4033 二分几何

参考:http://blog.csdn.net/libin56842/article/details/26618129

题意:给一个正多边形内点到其他顶点的距离(逆时针给出),求正多边形的边长

二分多边形的边长

根据余弦定理求出A的角度,之后求出所有角度,加起来是否为360,小于则扩大,大于则缩小边

Sample Input

2

3

3.0 4.0 5.0

3

1.0 2.0 3.0

Sample Output

Case 1: 6.766

Case 2: impossible

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 using namespace std;
 6 #define pi acos(-1.0)
 7 #define exp 1e-8
 8 int main()
 9 {
10     int t,n,i,j,flag,cas = 1;
11     double a[105];
12     scanf("%d",&t);
13     while(t--)
14     {
15         scanf("%d",&n);
16         flag = 0;
17         for(i = 0; i<n; i++)
18             scanf("%lf",&a[i]);
19         a[n] = a[0];
20         double l = 0,r = 20000,mid;
21         for(i = 1; i<=n; i++)
22         {
23             r = min(r,a[i]+a[i-1]);
24             l = max(l,fabs(a[i]-a[i-1]));
25         }
26         while(r-l>exp)
27         {
28             mid = (l+r)/2;
29             double s,sum=0;
30             for(i = 1; i<=n; i++)
31             {
32                 s = (a[i]*a[i]+a[i-1]*a[i-1]-mid*mid)/(2.0*a[i]*a[i-1]);
33                 sum+=acos(s);
34             }
35             if(fabs(sum-2*pi)<exp)
36             {
37                 flag = 1;
38                 break;
39             }
40             else if(sum>2*pi)
41                 r = mid;
42             else
43                 l = mid;
44         }
45         printf("Case %d: ",cas++);
46         if(flag)
47             printf("%.3f\n",mid);
48         else
49             printf("impossible\n");
50     }
51
52     return 0;
53 }
时间: 2024-08-13 12:45:01

hdu 4033 二分几何的相关文章

【二分+计算几何】hdu 4033 Regular Polygon

[二分+计算几何]hdu 4033 Regular Polygon 题目链接:hdu 4033 Regular Polygon 题目大意 已知正多边形中的一个内点到所有顶点的距离,求多边形的边长. 二分问题一般都存在含有一个未知量的方程(等式关系),通过二分未知量的范围实现查找,这道题目的几何关系就是:知道一边,内角和(围着内点)等于360度.根据三角不等式确定边的二分范围,二分查找边使得内角之和为2π即可. 说一下思路 笔者根据第一条边和最后一条边确定二分边的范围,边确定由余弦定理能确定所有内

hdu 2255 二分图带权匹配 模板题

模板+注解在 http://blog.csdn.net/u011026968/article/details/38276945 hdu 2255 代码: //KM×î´ó×îСƥÅä #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define INF 0x0fffffff const int MAXN

HDU 4709 Herding 几何题解

求所有点组成的三角形最小的面积,0除外. 本题就枚举所有可以组成的三角形,然后保存最小的就是答案了,因为数据量很少. 复习一下如何求三角形面积.最简便的方法就是向量叉乘的知识了. 而且是二维向量叉乘P1(ax, ay), P2(bx, by),公式为:|P1 X P2| = abs(ax*by - ay*bx) 三角形面积就是|P1 X P2| / 2; 本题也是float过不了,换成double就可以过了. const int MAX_N = 101; struct VertexPoint {

Hdu 2389 二分匹配

题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 2644    Accepted Submission(s): 823 Problem Description You’re giving a party in the garden of your villa by the sea. T

hdu 4737 二分或暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4737 Problem Description There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)

HDU 3656 二分+dlx判定

Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1308    Accepted Submission(s): 434 Problem Description A city's map can be seen as a two dimensional plane. There are N houses in

hdu 4033 2011成都赛区网络赛 余弦定理+二分 **

二分边长,判断最后内角和是否为2pi,注意l与r的选取,保证能组成三角形 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 10000

hdu 4033 Regular Polygon 计算几何 二分+余弦定理

题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #includ

HDU 4033

1 /* 2 http://acm.hdu.edu.cn/showproblem.php?pid=4033 3 题意:正n边形里面有一个点,知道这个点到n个顶点的距离,要求这个正多边形的边长 4 思路:在(0,20000)二分查找答案,用上余弦定理 5 2017年02月26日19:38:14 6 */ 7 #include <cstdio> 8 #include <cmath> 9 double len[110]; 10 int n; 11 double pi=acos(-1.0)