uva 12300 Smallest Regular Polygon(计算几何)
来源:互联网 发布:us域名注册 编辑:程序博客网 时间:2024/04/30 16:47
给定两点以及n,求出含这两点的正n边形的最小面积
反过来想,我们保证这条对角线是正n边形内的最长对角线即可
我的做法是分奇偶考虑,利用公式S = n×r×a/2
其中n为边数,r为边心距,a为边长
对应的是n个小三角形的面积
反正就是各种sin cos变形就好了
因为自己傻逼了。。。又跪了几发。。。
代码如下:
/* ***********************************************Author : yinwoodsE-Mail : yinwoods@163.comCreated Time : 2014年12月12日 星期五 21时50分20秒File Name : uva12300.cpp************************************************ */#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>#define MAXN 10010#define LL long long#define eps 1e-6#define PI 3.1415926535898using namespace std;struct Point { double x, y; Point() {} Point(double x_, double y_) { x = x_; y = y_; }};bool equ(double x) { return (x<eps&&(x>-eps));}double dist(Point p1, Point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}int main() { Point p1, p2; int n; double len, ang, r, a, s; while(scanf("%lf%lf%lf%lf%d", &p1.x, &p1.y, &p2.x, &p2.y, &n) != EOF) { if(equ(p1.x) && equ(p1.y) && equ(p2.x) && equ(p2.y) && n==0) break; len = dist(p1, p2); //printf("%lf\n", len); if(n % 2 == 0) { ang = (n-2.0)/(2.*n)*PI; r = len/2.0*sin(ang); a = len*cos(ang); s = n*a*r/2.0; //printf("r = %lf\ta = %lf\n", r, a); } else { ang = PI/(2.0*n); r = len/(cos(ang)*2.0)*cos(2.0*ang); a = 2.0*len*sin(ang); s = n*a*r/2.0; //printf("r = %lf\ta = %lf\n", r, a); } printf("%.6lf\n", s); } return 0;}
0 0
- UVA 12300 - Smallest Regular Polygon(计算几何)
- uva 12300 Smallest Regular Polygon(计算几何)
- uva 12300 - Smallest Regular Polygon(几何)
- Smallest Regular Polygon - UVa 12300 几何
- uva 12300 - Smallest Regular Polygon
- UVa 12300 Smallest Regular Polygon 正多边形内的计算
- hdu6055 Regular polygon(简单计算几何)
- 注意精度问题 UVA 12300 Smallest Regular Polygon
- Regular polygon(2017多校联赛2。 计算几何)
- HDU 6055 Regular polygon (计算几何 + 国家队论文结论)
- Regular Polygon - UVa 10824 几何+二分
- Regular Polygon - UVa 10824 几何暴力
- 【二分+计算几何】hdu 4033 Regular Polygon
- UVA12300-Smallest Regular Polygon
- UVA 12300 || Smallest Regular Polygon(给定两点,求穿过两点的最小正多边形
- HDU 6055 Regular polygon(几何)
- Regular polygon 数学几何
- uva 10173 Smallest Bounding Rectangle (计算几何-凸包)
- stm32时钟分析
- LeetCode刷题之三:判断两个二叉树是否相同
- 提升C++输入输出性能的三个方法
- UVA - 11059 Maximum Product
- bzoj1208: [HNOI2004]宠物收养所 SBT&&Splay
- uva 12300 Smallest Regular Polygon(计算几何)
- poj解题报告——1182
- gdb调试core文件
- Linux 0.11 malloc分析
- Cortex-M3 bit-band (位带)的学习
- 修改开机动画
- Ted演讲观后感 【Stop believing the pychics】
- 键盘上的所有快捷操作
- Hibernate 入门