poj1931

题意:看两个给定对应点的多边形是否经过位移,旋转,缩放可重叠。

分析:只需要判断每对应两点的距离是否成比例。注意:不只是相邻点,不相邻的也要判断。

计算好计算过程中数值的大小,那些需要用long long。

View Code
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
#include
< cmath >
using namespace std;

#define maxn 305

struct XPoint
{
int x, y;
XPoint()
{
}
XPoint(
int xx, int yy) :
x(xx), y(yy)
{
}
} aa[maxn], bb[maxn];

int n;

int len(XPoint & a, XPoint & b)
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

bool checkedge()
{
int a1 = len(aa[ 0 ], aa[ 1 ]);
int b1 = len(bb[ 0 ], bb[ 1 ]);
for ( int i = 0 ; i < n; i ++ )
for ( int j = 0 ; j < n; j ++ )
if (( long long ) a1 * len(bb[i], bb[j]) != ( long long ) b1 * len(aa[i],aa[j]))
return false ;
return true ;
}

int main()
{
// freopen("D:\\t.txt", "r", stdin);
while (scanf( " %d " , & n) != EOF && n != 0 )
{
bool flag = false ;
for ( int i = 0 ; i < n; i ++ )
scanf(
" %d%d " , & aa[i].x, & aa[i].y);
for ( int i = 0 ; i < n; i ++ )
scanf(
" %d%d " , & bb[i].x, & bb[i].y);
long long d1 = (aa[ 1 ].x - aa[ 0 ].x) * (aa[ 2 ].y - aa[ 0 ].y) - (aa[ 1 ].y - aa[ 0 ].y) * (aa[ 2 ].x - aa[ 0 ].x);
long long d2 = (bb[ 1 ].x - bb[ 0 ].x) * (bb[ 2 ].y - bb[ 0 ].y) - (bb[ 1 ].y - bb[ 0 ].y) * (bb[ 2 ].x - bb[ 0 ].x);
if (checkedge() && d1 * d2 >= 0 )
flag
= true ;
if (flag)
printf(
" similar\n " );
else
printf(
" dissimilar\n " );
}
return 0 ;
}

转载于:https://www.cnblogs.com/rainydays/archive/2011/03/16/1986391.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值