Fourth Point !!

链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1183

题目:
Given are the (
x;y
) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the
(
x;y
) coordinates of the fourth point.


题意:给出一个平行四边形的相邻两条边,求另一个点的坐标

分析:用数学中的向量和好解决,坑在需要判断相邻两边里三个点哪个是公共点,我的方法比较笨拙。

题解:
#include<iostream>

double s[8];
void change()
{
	double temp;
	if(s[0]==s[4]&&s[1]==s[5])
	{
		temp=s[0],s[0]=s[2],s[2]=temp;
		temp=s[1],s[1]=s[3],s[3]=temp;
	}
	else if(s[0]==s[6]&&s[1]==s[7])
	{
		temp=s[0],s[0]=s[2],s[2]=temp;
		temp=s[1],s[1]=s[3],s[3]=temp;
		temp=s[4],s[4]=s[6],s[6]=temp;
		temp=s[5],s[5]=s[7],s[7]=temp;
	}
	else if(s[2]==s[6]&&s[3]==s[7])
	{
		temp=s[4],s[4]=s[6],s[6]=temp;
		temp=s[5],s[5]=s[7],s[7]=temp;
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",s,s+1,s+2,s+3,s+4,s+5,s+6,s+7))
	{
		change();
		double ansx,ansy;
		ansx=s[6]+(s[0]-s[2]);
		ansy=s[7]+(s[1]-s[3]);
		printf("%.3lf %.3lf\n",ansx,ansy);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值