poj1931
题意:看两个给定对应点的多边形是否经过位移,旋转,缩放可重叠。
分析:只需要判断每对应两点的距离是否成比例。注意:不只是相邻点,不相邻的也要判断。
计算好计算过程中数值的大小,那些需要用long long。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
usingnamespace 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 ((longlong) a1 * len(bb[i], bb[j]) != (longlong) b1 * len(aa[i],aa[j]))
returnfalse;
returntrue;
}
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);
longlong 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);
longlong 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");
}
return0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
usingnamespace 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 ((longlong) a1 * len(bb[i], bb[j]) != (longlong) b1 * len(aa[i],aa[j]))
returnfalse;
returntrue;
}
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);
longlong 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);
longlong 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");
}
return0;
}