hdu 4033Regular Polygon(二分+余弦定理)
Regular Polygon
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 3274 Accepted Submission(s): 996
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.
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.
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”.
3
3.0 4.0 5.0
3
1.0 2.0 3.0
Case 2: impossible
#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(二分+余弦定理)的更多相关文章
- hdu 4033 Regular Polygon 计算几何 二分+余弦定理
题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. # ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- hdu 2413(最大匹配+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...
- HDU 5884 Sort (二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU 1025 DP + 二分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...
- hdu 2289 要二分的杯子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 5200 Trees 二分
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5200 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
随机推荐
- 只用css来美化的上传表单按钮(抄的迅雷的)
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>文件 ...
- Fragment 与 Fragment 相互传值
方法: 1 接口回调 2 用一个单例类 3 bundle 4 获取fragment实例 , setter getter 传值
- mysql查询中通配符的使用
mysql查询中通配符的使用 在mysql查询中经常会使用通配符,并且mysql的通配符和pgsql的存在区别(稍候再讨论),而且mysql中还可以使用正则表达式. SQL模式匹配: “_” ...
- virtualenv -- python虚拟沙盒(linux版本)
有人说:virtualenv.fabric 和 pip 是 pythoneer 的三大神器. 不管认不认同,至少要先认识一下,pip现在倒是经常用到,virtualenv第一次听说,不过,总得尝试一下 ...
- ARM处理器启动流程
根据<<芯片手册>>查看相关内容: 1.启动方式 2.地址布局 3.启动流程
- Servlet技术
Java Applet和Java Servlet都有一个共同特点: 它们都不是独立的应用程序,都没有main( )方法: 它们都不是由用户或者程序员直接调用,而是生存在容器中,由容器管理,Applet ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- BSGS模版 a^x=b ( mod c)
kuangbin的BSGS: c为素数: #define MOD 76543 int hs[MOD],head[MOD],next[MOD],id[MOD],top; void insert(int ...
- iOS - LocalCache 本地数据缓存
1.自定义方式本地数据缓存 1.1 自定义缓存 1 沙盒路径下的 Library/Caches 用来存放缓存文件,保存从网络下载的请求数据,后续仍然需要继续使用的文件,例如网络下载的离线数据,图片,视 ...
- JS 拼装代码的HTML onClick方法传递字符串
有时会在JS中拼装HTML代码,这时在HTML中出现的onClick()方法中: 1.出现传递Num型的数据,直接拼装进去即可: 2.可能会出现传递字符串的情况,处理方法比较特殊,如下: a:直接字符 ...