Erasing Edges - SGU 136(构造多边形)
题目大意:已知一个多边形上的每条边的中点,还原出来一个多边形。
分析:因为偶数是不固定的,所以可以为任意起点,奇数只有一个,可以所有中点加减算出来第一个点,然后就是简单的向量计算点的位置了......
==================================================================================================================
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const int MAXN = 10007; const double PI = acos(-1.0); const double EPS = 1e-7; struct point { double x, y; point(double x=0, double y=0):x(x),y(y){} point operator - (const point &tmp)const{ return point(x-tmp.x, y-tmp.y); } point operator + (const point &tmp)const{ return point(x+tmp.x, y+tmp.y); } point operator * (const int &t)const{ return point(x*t, y*t); } }Mid[MAXN], poly[MAXN]; int main() { int N; scanf("%d", &N); for(int i=1; i<=N; i++) { scanf("%lf%lf", &Mid[i].x, &Mid[i].y); if(i&1)poly[1] = poly[1]+Mid[i]; else poly[1] = poly[1]-Mid[i]; } for(int i=1; i<=N; i++) poly[i+1] = Mid[i] * 2 - poly[i]; if(poly[N+1].x != poly[1].x || poly[N+1].y != poly[1].y) printf("NO\n"); else { printf("YES\n"); for(int i=1; i<=N; i++) printf("%.3f %.3f\n", poly[i].x, poly[i].y); } return 0; }