POJ 1940 Polygon Programming with Ease(高斯消元)
2015-07-08 10:20
661 查看
Description
给出中点求顶点,顶点个数为奇数
Input
多组输入,每组用例占一行,第一个数为顶点数量,之后2*n个数表示n个中点的坐标,以文件尾结束输入
Output
对于每组用例,输出由给出n个中点组成的多边形的顶点坐标,保留六位小数
Sample Input
5 14 2 20 4 18 12 12 18 10 10
3 -3 5 -2 5 -3 6
3 -2 10 5 10 -1 12
Sample Output
5 10.000000 2.000000 18.000000 2.000000 22.000000 6.000000 14.000000 18.000000 10.000000 18.000000
3 -4.000000 6.000000 -2.000000 4.000000 -2.000000 6.000000
3 -8.000000 12.000000 4.000000 8.000000 6.000000 12.000000
Solution
用高斯消元可以推出第一个顶点坐标,之后递推求出其他点坐标即可
Code
给出中点求顶点,顶点个数为奇数
Input
多组输入,每组用例占一行,第一个数为顶点数量,之后2*n个数表示n个中点的坐标,以文件尾结束输入
Output
对于每组用例,输出由给出n个中点组成的多边形的顶点坐标,保留六位小数
Sample Input
5 14 2 20 4 18 12 12 18 10 10
3 -3 5 -2 5 -3 6
3 -2 10 5 10 -1 12
Sample Output
5 10.000000 2.000000 18.000000 2.000000 22.000000 6.000000 14.000000 18.000000 10.000000 18.000000
3 -4.000000 6.000000 -2.000000 4.000000 -2.000000 6.000000
3 -8.000000 12.000000 4.000000 8.000000 6.000000 12.000000
Solution
用高斯消元可以推出第一个顶点坐标,之后递推求出其他点坐标即可
Code
#include<cstdio> #include<iostream> double x[1010],y[1010],xx[1010],yy[1010]; int main() { int n; while(scanf("%d",&n)!=EOF) { int i; double a=0,b=0;//注意初始化 for(i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]); printf("%d",n);//按格式输出 for(i=1;i<=n;i++)//用高斯消元求出第一个点的坐标 { if(i&1) a+=x[i],b+=y[i]; else a-=x[i],b-=y[i]; } xx[1]=a; yy[1]=b; for(i=2;i<=n;i++)//递推求出其他点坐标 { xx[i]=xx[i-1]+2.0*(x[i-1]-xx[i-1]); yy[i]=yy[i-1]+2.0*(y[i-1]-yy[i-1]); } for(i=1;i<=n;i++) printf(" %.6lf %.6lf",xx[i],yy[i]); printf("\n"); } return 0; }
相关文章推荐
- 如何用好 Google 等搜索引擎
- Django用户认证系统(三)组与权限
- Algorithms—41.First Missing Positive
- Got fatal error 1236 from master when reading data from binary log
- logo设计中,你需要注意什么?
- Algorithms—38.Count and Say
- sessionStorage在Google_Chrome浏览器中的用法
- [Noip模拟赛] Polygon
- 给category添加基本数据类型属性
- ZXingObjC 64位 集成到自己的项目中(xcode 6.4)
- 【Go语言】【13】 4000 再谈GO语言的结构体
- 【Go语言】【13】再谈GO语言的结构体
- OC中的Category类别
- K-Nearest Neighbors algorithm
- Algorithms—33.Search in Rotated Sorted Array
- 给分类(Category)添加属性
- 聊一聊google的Knowledge Graph
- view设置gone的时候getHeight()的值
- django + uwsgi 配置
- Django DEBUG = False 引起的问题 django - Setting DEBUG = False causes 500 Error