#include <stdio.h>
#include <stdlib.h>
struct triangle {
double p1[2];
double p2[2];
double p3[2];
};
int congruence (struct triangle *, struct triangle *);
int congruence (struct triangle *a, struct triangle *b)
{
double w[2][3],t;
int i,j,k;
/* 各辺の長さの2乗を計算 */
t=a->p1[0]-a->p2[0];
w[0][0]=t*t;
t=a->p1[1]-a->p2[1];
w[0][0]+=t*t;
t=a->p2[0]-a->p3[0];
w[0][1]=t*t;
t=a->p2[1]-a->p3[1];
w[0][1]+=t*t;
t=a->p3[0]-a->p1[0];
w[0][2]=t*t;
t=a->p3[1]-a->p1[1];
w[0][2]+=t*t;
t=b->p1[0]-b->p2[0];
w[1][0]=t*t;
t=b->p1[1]-b->p2[1];
w[1][0]+=t*t;
t=b->p2[0]-b->p3[0];
w[1][1]=t*t;
t=b->p2[1]-b->p3[1];
w[1][1]+=t*t;
t=b->p3[0]-b->p1[0];
w[1][2]=t*t;
t=b->p3[1]-b->p1[1];
w[1][2]+=t*t;
/* sort */
for(k=0; k<2; k++) {
for(i=1; i<3; i++) {
for(j=0; j<i; j++) {
if(w[k][j]>w[k][i]) {
t=w[k][i];
w[k][i]=w[k][j];
w[k][j]=t;
}
}
}
}
/* 一致すれば合同 */
return ((w[0][0]==w[1][0])&&
(w[0][1]==w[1][1])&&
(w[0][2]==w[1][2])
);
}
int main()
{
struct triangle a,b;
a.p1[0]=0;
a.p1[1]=0;
a.p2[0]=0;
a.p2[1]=3.6;
a.p3[0]=4.7;
a.p3[1]=0;
b.p1[0]=2.1;
b.p1[1]=3.2;
b.p2[0]=2.1;
b.p2[1]=7.9;
b.p3[0]=5.7;
b.p3[1]=3.2;
printf("(%g, %g), ", a.
p1[0],a.
p1[1]); printf("(%g, %g), ", a.
p2[0],a.
p2[1]); printf("(%g, %g)\n",a.
p3[0],a.
p3[1]); printf("(%g, %g), ", b.
p1[0],b.
p1[1]); printf("(%g, %g), ", b.
p2[0],b.
p2[1]); printf("(%g, %g)\n",b.
p3[0],b.
p3[1]); if(congruence(&a,&b))
else
a.p1[0]=0;
a.p1[1]=0;
a.p2[0]=0;
a.p2[1]=3;
a.p3[0]=4;
a.p3[1]=0;
b.p1[0]=0;
b.p1[1]=0;
b.p2[0]=0;
b.p2[1]=6;
b.p3[0]=8;
b.p3[1]=0;
printf("(%g, %g), ", a.
p1[0],a.
p1[1]); printf("(%g, %g), ", a.
p2[0],a.
p2[1]); printf("(%g, %g)\n",a.
p3[0],a.
p3[1]); printf("(%g, %g), ", b.
p1[0],b.
p1[1]); printf("(%g, %g), ", b.
p2[0],b.
p2[1]); printf("(%g, %g)\n",b.
p3[0],b.
p3[1]); if(congruence(&a,&b))
else
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCB0cmlhbmdsZSB7CiAgZG91YmxlIHAxWzJdOwogIGRvdWJsZSBwMlsyXTsKICBkb3VibGUgcDNbMl07Cn07CgppbnQgY29uZ3J1ZW5jZSAoc3RydWN0IHRyaWFuZ2xlICosIHN0cnVjdCB0cmlhbmdsZSAqKTsKaW50IGNvbmdydWVuY2UgKHN0cnVjdCB0cmlhbmdsZSAqYSwgc3RydWN0IHRyaWFuZ2xlICpiKQp7CiAgZG91YmxlIHdbMl1bM10sdDsKICBpbnQgaSxqLGs7CgogIC8qIOWQhOi+uuOBrumVt+OBleOBrjLkuZfjgpLoqIjnrpcgKi8KICB0PWEtPnAxWzBdLWEtPnAyWzBdOwogIHdbMF1bMF09dCp0OwogIHQ9YS0+cDFbMV0tYS0+cDJbMV07CiAgd1swXVswXSs9dCp0OwoKICB0PWEtPnAyWzBdLWEtPnAzWzBdOwogIHdbMF1bMV09dCp0OwogIHQ9YS0+cDJbMV0tYS0+cDNbMV07CiAgd1swXVsxXSs9dCp0OwoKICB0PWEtPnAzWzBdLWEtPnAxWzBdOwogIHdbMF1bMl09dCp0OwogIHQ9YS0+cDNbMV0tYS0+cDFbMV07CiAgd1swXVsyXSs9dCp0OwoKICB0PWItPnAxWzBdLWItPnAyWzBdOwogIHdbMV1bMF09dCp0OwogIHQ9Yi0+cDFbMV0tYi0+cDJbMV07CiAgd1sxXVswXSs9dCp0OwoKICB0PWItPnAyWzBdLWItPnAzWzBdOwogIHdbMV1bMV09dCp0OwogIHQ9Yi0+cDJbMV0tYi0+cDNbMV07CiAgd1sxXVsxXSs9dCp0OwoKICB0PWItPnAzWzBdLWItPnAxWzBdOwogIHdbMV1bMl09dCp0OwogIHQ9Yi0+cDNbMV0tYi0+cDFbMV07CiAgd1sxXVsyXSs9dCp0OwoKICAvKiBzb3J0ICovCiAgZm9yKGs9MDsgazwyOyBrKyspIHsKICAgIGZvcihpPTE7IGk8MzsgaSsrKSB7CiAgICAgIGZvcihqPTA7IGo8aTsgaisrKSB7CiAgICAgICAgaWYod1trXVtqXT53W2tdW2ldKSB7CiAgICAgICAgICB0PXdba11baV07CiAgICAgICAgICB3W2tdW2ldPXdba11bal07CiAgICAgICAgICB3W2tdW2pdPXQ7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfQoKICAvKiDkuIDoh7TjgZnjgozjgbDlkIjlkIwgKi8KICByZXR1cm4gKCh3WzBdWzBdPT13WzFdWzBdKSYmCiAgICAgICAgICAod1swXVsxXT09d1sxXVsxXSkmJgogICAgICAgICAgKHdbMF1bMl09PXdbMV1bMl0pCiAgICAgICAgICk7Cgp9CgppbnQgbWFpbigpCnsKICBzdHJ1Y3QgdHJpYW5nbGUgYSxiOwoKICBhLnAxWzBdPTA7CiAgYS5wMVsxXT0wOwogIGEucDJbMF09MDsKICBhLnAyWzFdPTMuNjsKICBhLnAzWzBdPTQuNzsKICBhLnAzWzFdPTA7CgogIGIucDFbMF09Mi4xOwogIGIucDFbMV09My4yOwogIGIucDJbMF09Mi4xOwogIGIucDJbMV09Ny45OwogIGIucDNbMF09NS43OwogIGIucDNbMV09My4yOwoKICBwcmludGYoImlucHV0IGEgPSAiKTsKICBwcmludGYoIiglZywgJWcpLCAiLCBhLnAxWzBdLGEucD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