[UVA][何] 10445 - Make Polygon@Morris' Blog|PChome Online 人新台
2014-02-17 08:04:37| 人2,404| 回0 | 上一篇 | 下一篇

[UVA][何] 10445 - Make Polygon

0 收藏 0 0 站台

Problem B

Make Polygon

Input: standard input

Output: standard output

Time Limit: 2 seconds

 

Mr. Picasso is a geometry expert. Recently he invented a method of drawing polygon. He starts with a point and draw a line segment from the end point of the previous line segment in such a way so that except adjacent segments no two segments intersect. He finishes drawing when he returns to the starting point. Such a polygon is shown in the following figure.

 

In this problem you have to find the minimum and maximum angle of Picasso’s polygon.

 

Input

Each input starts with an integer, N (3<=N<=20). In the following N lines there are two integers indicating the Cartesian coordinate of the end points of line segments drawn by Picasso. The absolute value of each co-ordinate will not cross 1000. Input is terminated when N is less than 3.

 

Output

For each line of input print the value of minimum and maximum angles of Picasso’s Polygon in degree. Use 6 digits precision.

 

Sample Input

3
0 0
10 0
0 10
4
0 0
10 0
10 10
0 10
0

 

Sample Output

45.000000 90.000000
90.000000 90.000000

______________________________________________________________________________
(Problem-setter: Md. Kamruzzaman, BUET Sprinter)

目描述:

一多形,求角的最大最小值何 ?

定方式 或 逆 序都有可能。

目解法:


首先要搞定到底是是逆,

挑出最界的一,再查找近,入整成一序。

接著利用相所的角度,得到角的角度。

// 用了其他奇怪的做法,一直卡 WA ...

#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
struct Pt {
    double x, y;
    Pt(double a=0, double b=0):
        x(a), y(b) {}
    bool operator<(const Pt &a) const {
        if(fabs(x - a.x) > eps)
            return x < a.x;
        return y < a.y;
    }    
    Pt operator-(const Pt &a) const {
        Pt ret;
        ret.x = x - a.x;
        ret.y = y - a.y;
        return ret;
    }
};
struct Vec {
    double x, y;
    Vec(double a=0, double b=0):
        x(a), y(b) {}
    Vec(Pt a):
        x(a.x), y(a.y) {}
};
double cross(Vec a, Vec b) {return a.x * b.y - a.y * b.x;}
double dot(Vec a, Vec b) {return a.x * b.x + a.y * b.y;}
double len(Vec a) {return sqrt(a.x * a.x + a.y * a.y);}
double radian2(Vec a, Vec b) {return acos(dot(a, b)/len(a)/len(b));}
double radian2deg(double radian) {return radian / pi * 180;}
int main() {
    for(int n; scanf("%d", &n) == 1 && n >= 3;) {
        int i, j, k;
        Pt D[25];
        for(i = 0; i < n; i++)
            scanf("%lf %lf", &D[i].x, &D[i].y);
        int top_right = 0;
        for(i = 0; i < n; i++) {
            if(D[top_right] < D[i])
                top_right = i;
        }
        if(D[(top_right-1+n)%n].y > D[(top_right+1)%n].y)
            reverse(D, D+n);
        double mndeg = 2 * pi, mxdeg = 0;
        double angle[25];
        for(i = 0; i < n; i++) {
            double vx, vy;
            vx = D[i].x - D[(i-1+n)%n].x;
            vy = D[i].y - D[(i-1+n)%n].y;
            angle[i] = atan2(vy, vx);
        }
        for(i = 0; i < n; i++) {
            double theta = fmod(pi - (angle[i] - angle[(i-1+n)%n]) + 2 * pi, 2 * pi);
            mndeg = min(mndeg, theta);
            mxdeg = max(mxdeg, theta);
        }
        printf("%.6lf %.6lf\n", radian2deg(mndeg), radian2deg(mxdeg));
    }
    return 0;
}

台: Morris
人(2,404) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA] 10471 - Can't be too GREEDY
此分上一篇:[UVA] 10423 - Peter Takes a Tramway

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86