136. Erasing Edges

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

Little Johnny painted on a sheet of paper a polygon with N vertices. Then, for every edge of the polygon, he drew the middle point of the edge. After that, he went to school. When he came back, he found out that his brother had erased the polygon (both the edges and the vertices). The only thing left were the middle points of the edges of the polygon. Help Johnny redraw his polygon.

Input

The first line of the input contains the integer number N (3<=N<=10 000). Then, N lines will follow, each of them containing real numbers, separated by blanks: xi and yi(xi,yi) are the coordinates of the middle point of the edge #i. The coordinates will be given with at most 3 decimal places.

Output

Print a line containing the word "YES", if the polygon can be redrawn, or "NO", if there exists no polygon having the given coordinates for the middle points of its edges. If the answer is "YES", then you should print N more lines, each of them containing two real numbers, separated by a blank, representing the X and Y coordinates of the vetices of the polygon. The coordinates should be printed with at least 3decimal places. You should output the cordinates for vertex #1 first, for vertex #2 second and so on.. In order to decide which vertex of the polygon is #1,#2,..,#N, you should know that for every 1<=i<=N-1, edge #i connects the vertices labeled i and i+1. Edge #N connects the vertices N and 1.

Hint

The polygon may contain self-intersections. Although in many geometric problems, self-intersections only make things more difficult, in this case, they make things a lot easier.

Sample Input #1

4
0 0
2 0
2 2
0 2

Sample Output #1

YES
-1.000 1.000
1.000 -1.000
3.000 1.000
1.000 3.000

Sample Input #2

4
0 0
2 0
2 2
1 3

Sample Output #2

NO
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct pnt{
double x,y;
};
const int maxn=10001;
const double eps=1e-9;
pnt p[maxn];
int n;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double lvaluex=0,lvaluey=0;
int cnt=1;
for(int i=n-1;i>0;i--){
lvaluex+=cnt?p[i].x:-p[i].x;
lvaluey+=cnt?p[i].y:-p[i].y;
cnt^=1;
}
if((n&1)==0&&n>2&&(fabs(lvaluex-p[0].x)>eps||fabs(lvaluey-p[0].y)>eps)){puts("NO");return 0;}
puts("YES");
double x=(p[0].x+lvaluex);
double y=(p[0].y+lvaluey);
for(int i=0;i<n;i++){
printf("%.3f %.3f\n",x,y);
x=p[i].x*2-x;
y=p[i].y*2-y;
}
return 0;
}

  

快速切题 sgu136. Erasing Edges的更多相关文章

  1. 快速切题 sgu134.Centroid 树形dp

    134. Centroid time limit per test: 0.25 sec. memory limit per test: 4096 KB You are given an undirec ...

  2. Erasing Edges - SGU 136(构造多边形)

    题目大意:已知一个多边形上的每条边的中点,还原出来一个多边形. 分析:因为偶数是不固定的,所以可以为任意起点,奇数只有一个,可以所有中点加减算出来第一个点,然后就是简单的向量计算点的位置了...... ...

  3. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  4. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  5. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  6. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  7. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  8. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  9. 快速切题 sgu117. Counting 分解质因数

    117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...

随机推荐

  1. 第1章 1.6计算机网络概述--OSI参考模型

    ISO七层模式:国际标准组织对互联网通信规则进行的定义. 7.应用层:所有能产生网络流量的程序,如:QQ. 6.表示层:传输前对数据进行进行处理,是一种数据处理的规则,如:加密.压缩.传输二进制(图片 ...

  2. python模块之subprocess模块

    简述 subprocess意在替代其他几个老的模块或者函数,比如:os.system os.spawn* os.popen* popen2.* commands.*subprocess最简单的用法就是 ...

  3. mysql性能测试--sysbench实践

    mysql性能测试--sysbench实践 Sysbench   业界较为出名的性能测试工具 可以测试磁盘,CPU,数据库 支持多种数据库:oracle,DB2,MYSQL 需要自己下载编译安装 建议 ...

  4. webdriver js点击无法点击的元素

    原文地址https://blog.csdn.net/galen2016/article/details/56847545 [WebDriver]调用JavaScript 一.WebDriver 提供了 ...

  5. JS随机数种子

    JS随机数种子 1 试着想一下,如果在某一个场景,我们做一个游戏,用户玩到一半的时候退出了,这样 用户下次进来可以选择继续上一次的进度继续玩,那么现在问题来了:用户玩 的进度以及用户的积分等简单的描述 ...

  6. 587. Erect the Fence(凸包算法)

    问题 给定一群树的坐标点,画个围栏把所有树围起来(凸包). 至少有一棵树,输入和输出没有顺序. Input: [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]] Output: ...

  7. Sublime Text 3 配置Python3.x

    Sublime Text 3 配置Python3.x 一.Package Control 安装: 1,通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴 ...

  8. LM358电流检测电路

    ----------------------------------------------------------------------------------------- ---------- ...

  9. git使用合集

    1.git 克隆时重命名本地文件夹或目录 如:git clone https://github.com/torvalds/linux.git linux_kernel 2.git查看tag git t ...

  10. 将vi打造成IDE

    一.环境 发行版:Ubuntu 18.04 LTS 代号:bionic 内核版本:4.15.0-33-generic 二.步骤 2.1 准备工作 sudo apt-get install python ...