Regular Polygon

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 3274    Accepted Submission(s): 996

Problem Description
In
a 2_D plane, there is a point strictly in a regular polygon with N
sides. If you are given the distances between it and N vertexes of the
regular polygon, can you calculate the length of reguler polygon's side?
The distance is defined as dist(A, B) = sqrt( (Ax-Bx)*(Ax-Bx) +
(Ay-By)*(Ay-By) ). And the distances are given counterclockwise.
 
Input
First
a integer T (T≤ 50), indicates the number of test cases. Every test
case begins with a integer N (3 ≤ N ≤ 100), which is the number of
regular polygon's sides. In the second line are N float numbers,
indicate the distance between the point and N vertexes of the regular
polygon. All the distances are between (0, 10000), not inclusive.
 
Output
For
the ith case, output one line “Case k: ” at first. Then for every test
case, if there is such a regular polygon exist, output the side's length
rounded to three digits after the decimal point, otherwise output
“impossible”.
 
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
 
Source
 
  已知一个点到正n边形的n个顶点的距离,求正n边形的边长。
思路:
       在已知的表达式中,求不出n边形的边长。但是依据两边之和大于第三边,两边之差小鱼第三边。可以得到这个边的范围.
   然后由于n边形的以任意一个点,连接到所有顶点,所有的夹角之和为360,所以只需要采取二分依次来判断,是否满足。
 
代码:
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define pi acos(-1.0)
#define esp 1e-8
using namespace std;
double aa[];
int main()
{
int cas,n;
double rr,ll;
scanf("%d",&cas);
for(int i=;i<=cas;i++)
{
scanf("%d",&n);
for(int j=;j<n;j++)
scanf("%lf",aa+j);
//确定上下边界
ll=,rr=;
for(int j=;j<n;j++)
{
rr=max(rr,aa[j]+aa[(j+)%n]);
ll=min(ll,fabs(aa[j]-aa[(j+)%n]));
}
double mid,sum,cosa;
printf("Case %d: ",i);
bool tag=;
while(rr>esp+ll)
{
mid=ll+(rr-ll)/;
sum=;
for(int j=;j<n;j++){
//oosr=a*a+b*b-mid*mid; 余弦定理求夹角,然后判断所有的夹角之和是否为360
cosa=(aa[j]*aa[j]+aa[(j+)%n]*aa[(j+)%n]-mid*mid)/(2.0*aa[j]*aa[(j+)%n]);
sum+=acos(cosa);
}
if(fabs(sum-*pi)<esp){
tag=;
printf("%.3lf\n",mid);
break;
}
else
if(sum<*pi) ll=mid;
else
rr=mid;
}
if(tag==)
printf("impossible\n");
}
return ;
}

hdu 4033Regular Polygon(二分+余弦定理)的更多相关文章

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

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

  2. UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)

    UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...

  3. hdu 2413(最大匹配+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...

  4. HDU 5884 Sort (二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...

  5. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  6. HDU 1025 DP + 二分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...

  7. hdu 2289 要二分的杯子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...

  8. HDU 1025 LIS二分优化

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...

  9. HDU 5200 Trees 二分

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5200 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

随机推荐

  1. Devexpress TreeList选择父级联动

    Treelist当显示复选框后,父级和子级的复选框没有关联,使用过程中很不便,如图所示 自己给treelist添加父子级联动 /// <summary> /// 初始化TreeList,父 ...

  2. Queue 应用——拓扑排序

    1. 拓扑排序 题目描述:对一个有向无环图(Directed Acyclic Graph, DAG)G进行拓扑排序,是将G中所有顶点排成线性序列,是的图中任意一堆顶点u和v,若边(u, v)在E(G) ...

  3. [HDOJ2717]Catch That Cow

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. session 登陆浏览,并实现session注销登陆

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  5. servlet&jsp高级:第五部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. poj 1066 线段相交

    链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  7. monkeyrunner自动登录脚本

    自己写了个平时测试的app的自动登录脚本,亲测可运行.读者参照时只需要改包名.activity名称.坐标值.账号和密码即可 查看坐标是多少的方法:使用手机的指针位置来实现:系统设置---开发者选项-- ...

  8. hdu 3054 Fibonacci 找循环节的公式题

    Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Proble ...

  9. c++ 操作符 重载。

    操作符如关系操作符,全局函数的话,必须第一个是class. 1.赋值(=),下标([ ]),调用(())和成员访问箭头(->)等操作符必须定义为成员,如果定义为非成员的话,程序在编译的时候,会发 ...

  10. 可重入锁 & 自旋锁 & Java里的AtomicReference和CAS操作 & Linux mutex不可重入

    之前还是写过蛮多的关于锁的文章的: http://www.cnblogs.com/charlesblc/p/5994162.html <[转载]Java中的锁机制 synchronized &a ...