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 ...
随机推荐
- ios照片获取,拍照功能
// // HYBPhotoPickerManager.h // ehui // // Created by 黄仪标 on 14/11/26. // Copyright (c) 2014年 黄 ...
- 搭建本地的git仓库
折腾了快一天了,终于搭建成功了. 分享一下搭建的步骤: 一.GIT仓库的创建 1. adduser git 2. passwd git 此例设置git的密码为123456 3. cd /home/gi ...
- MySQL(二) —— 数据类型与操作数据表
数据类型 数据类型是指列.存储过程参数.表达式和局部变量的数据特征,它决定了数据的存储格式,代表了不同的信息类型. 整型:TYNINT(-2^7 ~ 2^7-1); SMALLINT(-2^15 ~ ...
- [C程序设计语言]第五部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- So easy Webservice 6.使用EndPoint发布webservice服务
创建第一个Web服务: @WebService // 添加了此注解,代表是一个WebService public class HelloWorld { // 非 static final privat ...
- Linux命令工具基础04 磁盘管理
Linux命令工具基础04 磁盘管理 日程磁盘管理中,我们最常用的有查看当前磁盘使用情况,查看当前目录所占大小,以及打包压缩与解压缩: 查看磁盘空间 查看磁盘空间利用大小 df -h -h: huma ...
- python_way ,自定义session
python_way ,自定义session container = {} #可以是数据库,可以是缓存也可以是文件 class Session: def __init__(self, handler) ...
- 《FLASH CC 2015 CANVAS 中文教程》——1、导出canvas动画,文件结构浅析
注::如果你对 FLASH 这个软件操作不够熟悉,建议你可以先看看FLASH动画之类的书. :FLASH CC 在文中直接简称为CC. :以下所以文章中所说的快捷键 如果你按了不起作用,请检查是否有其 ...
- iOS - OC 异常处理
1.@try 语句 @try { // Code that can potentially throw an exception 可能会抛出异常的代码块 statement . . . } @catc ...
- c++复习一:复数运算的简单实现。
复数运算的简单实现. 程序很简单了.基本忘光了复数,重新了解了基本概念.如何在平面表示一个复数,复数的长度|x|=开根 a^2+b^2.和四则运算. 程序基本点: 封装和抽象: 1)封装成员数据,私有 ...