快速切题 sgu136. Erasing Edges
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 2 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的更多相关文章
- 快速切题 sgu134.Centroid 树形dp
134. Centroid time limit per test: 0.25 sec. memory limit per test: 4096 KB You are given an undirec ...
- Erasing Edges - SGU 136(构造多边形)
题目大意:已知一个多边形上的每条边的中点,还原出来一个多边形. 分析:因为偶数是不固定的,所以可以为任意起点,奇数只有一个,可以所有中点加减算出来第一个点,然后就是简单的向量计算点的位置了...... ...
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 快速切题 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 ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
随机推荐
- Linux环境下proc的配置c/c++操作数据库简单示例
在虚拟机上装了oracle11g数据库,原本想利用c/c++学习操作数据库.结果感觉摊上了一个大坑.从安装好oracle数据库到配置好proc的编译选项整整花了二天.但让我意识到自己自己几点薄弱:1. ...
- receive.denyCurrentBranch 推送错误解决
场景: 1.搭建Ok了一git服务器 2.本机上的现有源码,现在想纳入git源码管理 操作: 1.服务器上创建了工程仓库 git init 2. 客户端使用tortoisegit添加并提交要纳入源码管 ...
- 把大象装进冰箱的N种方法
作者:折剑头链接:https://www.zhihu.com/question/49214119/answer/115728034来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- cocos2d 特效
一.特效概念 特效是让精灵(CCSprite)执行某种特殊的效果.其实,特效也是一种动画! 但是,为什么要把特效与动画区分呢?因为,特效是基于网格属性来进行的. 如何区分动画与特效?简单的将,当使用到 ...
- Mirror--镜像相关操作
其他相关操作1. 关闭镜像--关闭镜像USE [master]GOALTER DATABASE Demo1 SET PARTNER OFFGO 2. 证服务器--移除见证服务器USE [master ...
- java 字节流和字符流转换类InputStreamReader,OutPutStreamReader
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2pjMjExMzIy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- CentOS7.5基础优化与常用配置
目录 最小化全新安装CentOS7基础优化 配置yum源 安装常用软件 关闭防火墙 关闭SELinux 优化ulimit 历史命令记录改为1万条 把命令提示符改为绿色 添加vim配置文件 添加一个普通 ...
- java Pattern(正则)类
Pattern的静态方法matches 用于快速匹配字符串,该方法适合用于只匹配一次,且匹配全部字符串. Boolean b=Pattern.matches("^((13[0-9])|(15 ...
- 2018年浙江中医药大学程序设计竞赛 Solution
Problem A. Jhadgre的C语言程序 签. #include <bits/stdc++.h> using namespace std; int main() { puts(&q ...
- QML基本可视化元素--Text
一个Text项目可以显示纯文本或者富文本 1. 可以使用Html标记:text: “<b>HELLO</b>” 2. 宽度和高度(width, height): ...