24h購物| | PChome| 登入
2014-03-02 20:25:57| 人氣1,664| 回應0 | 上一篇 | 下一篇

[UVA][圓周角] 12395 - Regular Convex Polygon

推薦 0 收藏 0 轉貼0 訂閱站台


  Regular Convex Polygon 

A regular convex polygon is a polygon where each side has the same length, and all interior angles are equal and less than 180 degrees. A square, for example, is a regular convex polygon. You are given three points which are vertices of a regular convex polygon R; can you determine the minimum number of vertices that R must have?

Input 

Each test case consists of three lines. Line i consists of two floating point values xi and yi ( -104$ le$x1, y1$ le$104) where (xi, yi) are the coordinates of a vertex of R. The coordinates are given with a precision of 10-6, i.e., they differ from the exact coordinates by at most 10-6. You may assume that for each test case the Euclidean distance between any two given points is at least 1, and R has at most 1000 vertices. The input will finish with a line containing the word END.

Output 

For each test case, print one line with the minimum number of vertices that R must have.

Sample Input 

-1385.736326 -146.954822
430.000292 -2041.361203
1162.736034 478.316025
0.000000 4147.000000
-4147.000000 0.000000
0.000000 -4147.000000
END

Sample Output 

3
4


圓周角定義(wiki) :
在幾何學中,當圓的兩條割線在圓上相遇時,就會形成圓周角。 一般來說,圓周角可被視為共用一個端點的兩條弦。

圓周角 = 所含夾角的一半

#include <stdio.h>
#include <math.h>
using namespace std;
int mod0(double a, double b) {
    return fmod(a, b) < 1e-8 || fabs(fmod(a, b) - b) < 1e-8;
}
int main() {
    double x1, x2, x3;
    double y1, y2, y3;
    const double pi = acos(-1);
    while(scanf("%lf %lf", &x1, &y1) == 2) {
        scanf("%lf %lf", &x2, &y2);
        scanf("%lf %lf", &x3, &y3);
        double a, b, c, ta, tb, tc;
        a = hypot(x1 - x2, y1 - y2);
        b = hypot(x3 - x2, y3 - y2);
        c = hypot(x1 - x3, y1 - y3);
        ta = acos((b*b + c*c - a*a) / (2*b*c));
        tb = acos((a*a + c*c - b*b) / (2*a*c));
        tc = acos((a*a + b*b - c*c) / (2*a*b));
        ta = ta * 2;
        tb = tb * 2;
        tc = tc * 2;
        for(int i = 3; i <= 1000; i++) {
            double theta = 2 * pi / i;
            if(mod0(ta, theta) && mod0(tb, theta) && mod0(tb, theta))
                printf("%d\n", i), i = 1024;
        }
    }
    return 0;
}


台長: Morris
人氣(1,664) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][最大平均值問題] 1451 - Average
此分類上一篇:[UVA][DP] 11617 - An Odd Love

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文