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 ...
随机推荐
- UVA 1252 十五 Twenty Questions
十五 Twenty Questions Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- unity3d 游戏对象消失三种方法的区别(enabled/Destroy/active)
gameObject.renderer.enabled //是控制一个物体是否在屏幕上渲染或显示 而物体实际还是存在的 只是想当于隐身 而物体本身的碰撞体还依然存在的 GameObject.Destr ...
- Cheatsheet: 2014 12.01 ~ 12.31
.NET Some Thoughts on the new .Net Introducing .NET Core Running ASP.NET on a Raspberry Pi with Mono ...
- FreeSWITCH第三方库(视频)的简单介绍(二)
FreeSWITCH使用了大量的第三方库,本文档主要介绍视频相关库的信息: 音频相关库的信息介绍参考:http://www.cnblogs.com/yoyotl/p/5486753.html 其他相关 ...
- python_way ,自定义session
python_way ,自定义session container = {} #可以是数据库,可以是缓存也可以是文件 class Session: def __init__(self, handler) ...
- .Net 使用文件上传控件FileUpload上传图片
例1: 来源:http://long546324.iteye.com/blog/349946 Default.aspx文档: <%@ Page Language="C#" A ...
- SAP接口编程 之 JCo3.0系列(04) : 会话管理
在SAP接口编程之 NCo3.0系列(06) : 会话管理 这篇文章中,对会话管理的相关知识点已经说得很详细了,请参考.现在用JCo3.0来实现. 1. JCoContext 如果SAP中多个函数需要 ...
- OCR识别-python版(一)
需求:识别图片中的文字信息环境:windows系统 开发语言:python 使用工具类:1.pyocr 2.PIL 3.tesseract-ocr 步骤: 1.pyocr 网络通直接使用命令:pip ...
- hostapd源代码分析(二):hostapd的工作机制
[转]hostapd源代码分析(二):hostapd的工作机制 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004433 在我的上一 ...
- ctrl+enter提交留言
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...