您的位置:首页 > 编程语言 > Go语言

zoj 1974 || poj 1940 Polygon Programming with Ease

2011-05-01 14:14 357 查看
1973是给出顶点求中点,这个是给出中点求顶点。



和会升讨论了下,发现可以用一个顶点去替代所有顶点,然后解方程。后来我发现,如果是偶数点的话,最后那个顶点的坐标被消去了!不过还好,给的是奇数个顶点。偶数边的话,结果是不唯一的,自己手动模拟下就知道啦。



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

const int MAX = 1010;
struct point{ double x,y;};
point p[MAX];
double disp2p(point a,point b)
{
	return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
point s[MAX];
int main()
{
	int n;
	while( ~scanf("%d",&n) )
	{
		for(int i=0; i<n; i++)
			scanf("%lf %lf",&p[i].x,&p[i].y);
		double sumy = 0.0,sumx = 0.0;
		for(int i=0; i<n; i++)
			if( i % 2 == 0 )
			{
				sumx += p[i].x;
				sumy += p[i].y;
			}
			else
			{
				sumx -= p[i].x;
				sumy -= p[i].y;
			}
		s[0].x = sumx; s[0].y = sumy;
		printf("%d %.6lf %.6lf",n,s[0].x,s[0].y);
		for(int i=1; i<n; i++)
		{
			s[i].x = 2*p[i-1].x-s[i-1].x;
			s[i].y = 2*p[i-1].y-s[i-1].y;
			printf(" %.6lf %.6lf",s[i].x,s[i].y);
		}
		printf("/n");
	}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: