uva 12300

题意:给定两个点A和B,求穿过这两个点的面积最小的正n边形的面积。

题解:画图就能推断,AB连线一定是n边形第0个点和第n/2个点的连线,因为这条连线是正n边形最长的一条边,这样面积才能最小,正n边形的面积 S = 边心距 * 周长 / 2。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1);
struct Point {
    double x, y;
    Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;
double dcmp(double x) {
    if (fabs(x) < eps)
        return 0;
    return x < 0 ? -1 : 1;
}
Vector operator + (const Point& A, const Point& B) {
    return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (const Point& A, const Point& B) {
    return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (const Point& A, double a) {
    return Vector(A.x * a, A.y * a);
}
Vector operator / (const Point& A, double a) {
    return Vector(A.x / a, A.y / a);
}
double Cross(const Vector& A, const Vector& B) {
    return A.x * B.y - A.y * B.x;
}
double Dot(const Vector& A, const Vector& B) {
    return A.x * B.x + A.y * B.y;
}
double Length(const Vector& A) {
    return sqrt(Dot(A, A));
}
bool operator < (const Point& A, const Point& B) {
    return A.x < B.x || (A.x == B.x && A.y < B.y);
}
bool operator == (const Point& A, const Point& B) {
    return A.x == B.x && A.y == B.y;
}
double torad(double deg) {
    return deg / 180.0 * PI;
}

int main() {
    Point A, B;
    int n;
    while (scanf("%lf%lf%lf%lf%d", &A.x, &A.y, &B.x, &B.y, &n) == 5 && dcmp(A.x + A.y + B.x + B.y + n)) {
        if (n % 2) {
            double len = Length(A - B);
            int m = n / 2;
            double rad1 = torad(360.0 / n * m / 2.0);
            double a1 = len / 2.0 / sin(rad1);
            double rad = torad(360.0 / (2.0 * n));
            double h = a1 * cos(rad);
            double a = a1 * sin(rad) * 2;
            double s = a * n * h / 2;
            printf("%lf\n", s);
        }
        else {
            double len = Length(A - B);
            double rad = torad(360.0 / (2.0 * n));
            double h = len / 2.0 * cos(rad);
            double a = len * sin(rad);
            double s = a * n * h / 2;
            printf("%lf\n", s);
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-13 09:35:41

uva 12300的相关文章

UVA 12300 - Smallest Regular Polygon(计算几何)

思路:找对点最优,奇数情况下,半径要另外算 大概这么一个图,偶数就是距离的一半,奇数的话,做一个正2N边形,那么半径就可以利用三角函数算出来了 然后有了外切圆半径,就能算面积了,为sin(2pi / n) * r * r * n / 2 代码: #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const double

几何基础专题

UVA 11437 Triangle Fun UVA 11800 Determine the Shape 四边形判定 UVA 11646 Athletics Track UVA 11817 Tunnelling the Earth 球面距离 UVA 1473 Dome of Circus UVA 11524 InCircle UVA 11731 Ex-circles 旁切圆 UVA 12300 Smallest Regular Polygon UVA 10566 Crossed Ladders

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica

[2016-02-03][UVA][514][Rails]

时间:2016-02-03 22:24:52 星期三 题目编号:UVA 514 题目大意:给定若干的火车(编号1-n),按1-n的顺序进入车站, 给出火车出站的顺序,问是否有可能存在 分析:    FIFO,用栈模拟一遍即可, 方法:    根据输入的顺序,从1-n开始,当前操作的为i 如果i是当前对应的编号,那么直接跳过(进入B) 如果不是,根据当前需求的编号,小于i,就从栈顶弹出一个元素, 看这个元素是否是需求的,是则继续.否则NO 1 2 3 4 5 6 7 8 9 10 11 12 13