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;
}

 

转载于:https://www.cnblogs.com/liuxin13/p/4856829.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值