1939:Diplomatic License

keyword

平面幾何 C++

概要

n角形(nは奇数)が与えられる。中点を結んだ多角形を出力する問題。
単に中点を順に出力するだけ。

int main(){
    int n, i;
    while(scanf("%d",&n)!=EOF){
        vector<double> xs, ys;
        xs.reserve(n+2);
        ys.reserve(n+2);
        REP(i,n){
            double x, y;
            scanf("%lf%lf",&x,&y);
            xs.PB(x);
            ys.PB(y);
        }
        xs.PB(xs[0]);
        ys.PB(ys[0]);
        printf("%d ",n);
        REP(i,n){
            printf("%.6f %.6f%c",
            (xs[i]+xs[i+1])*0.5+EPS, (ys[i]+ys[i+1])*0.5+EPS,
            (i==n-1)?'\n':' ');
        }
    }

    return 0;
}