Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<memory.h>
- #include<map>
- #include<set>
- #include<queue>
- #include<list>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- using namespace std;
- struct point {
- private: double x, y;
- public:
- point() : x(0), y(0) {}
- point(double x, double y) : x(x), y(y) {}
- void scan() {
- scanf("%lf%lf", &x, &y);
- }
- point operator+ (const point & P) const {
- return point(x + P.x, y + P.y);
- }
- point operator- (const point & P) const {
- return point(x - P.x, y - P.y);
- }
- point operator/ (double k) const {
- return point(x / k, y / k);
- }
- bool operator== (const point & P) const {
- return x == P.x && y == P.y;
- }
- double operator*(const point & P) const {
- return x * P.y - y * P.x;
- }
- point operator*(double k) const{
- return point(x * k, y * k);
- }
- double operator%(const point & p) const{
- return x * p.x + y * p.y;
- }
- double dist(const point & P) const {
- point r = P - *this;
- return hypot(r.x, r.y);
- }
- double getAngle(point u) const{
- point v = *this;
- return atan2(v * u, v % u);
- }
- point rotate() const{
- return point(-y, x);
- }
- point rotate(double cosa, double sina) const
- {
- point v = *this;
- point u = v.rotate();
- point w = v * cosa + u * sina;
- return w;
- }
- point rotate(double alpha) const{
- return rotate(cos(alpha), sin(alpha));
- }
- };
- double triangleArea(point & A, point & B, point & C) {
- return abs((A - B) * (C - B)) * 0.5;
- }
- point f[3];
- point s[3];
- bool is0() {
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- for (int z = 0; z < 3; z++) {
- if (i == j || j == z || z == i) continue;
- if (f[i] == s[0] && f[j] == s[1] && f[z] == s[2])
- return true;
- }
- }
- }
- return false;
- }
- bool isEquals() {
- double sidef[3]{ f[0].dist(f[1]), f[1].dist(f[2]), f[0].dist(f[2]) };
- double sides[3]{ s[0].dist(s[1]), s[1].dist(s[1]), s[0].dist(s[2]) };
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- for (int z = 0; z < 3; z++) {
- if (i == j || j == z || z == i) continue;
- if (sidef[i] == sides[0] && sidef[j] == sides[1] && sidef[z] == sides[2])
- return true;
- }
- }
- }
- return false;
- }
- int idMax(point A, point B, point C) {
- double angles[3]{ A.getAngle(B), B.getAngle(C), A.getAngle(C) };
- double mx = angles[0];
- int id = 0;
- for (int i = 1; i < 3; i++) {
- if (mx < angles[i]) {
- mx = angles[i];
- id = i;
- }
- }
- return id;
- }
- int idMin(point A, point B, point C) {
- double angles[3]{ A.getAngle(B), B.getAngle(C), A.getAngle(C) };
- double mx = angles[0];
- int id = 0;
- for (int i = 1; i < 3; i++) {
- if (mx > angles[i]) {
- mx = angles[i];
- id = i;
- }
- }
- return id;
- }
- int main(){
- for (int i = 0; i < 3; i++) {
- f[i].scan();
- }
- for (int i = 0; i < 3; i++) {
- s[i].scan();
- }
- double fs = triangleArea(f[0], f[1], f[2]);
- double ss = triangleArea(s[0], s[1], s[2]);
- if (fs != ss) {
- printf("5");
- return 0;
- }
- if (is0) {
- printf("0");
- return 0;
- }
- if (!isEquals()) {
- printf("4");
- return 0;
- }
- double len = f[0].dist(s[0]);
- bool p = false;
- for (int i = 1; i < 3; i++) {
- if (f[i].dist(s[i]) != len) {
- p = false;
- }
- }
- if (p) {
- printf("1");
- return 0;
- }
- int mf = idMax(f[0], f[1], f[2]);
- int ms = idMax(s[0], s[1], s[2]);
- for (int i = 0; i < 3; i++) {
- f[i] = f[i] - f[mf];
- s[i] = s[i] - s[ms];
- }
- int mxf = idMin(f[0], f[1], f[2]);
- int mxs = idMin(s[0], s[1], s[2]);
- double alpha = f[mxf].getAngle(s[mxs]);
- for (int i = 1; i < 3; i++) {
- f[i].rotate(alpha);
- s[i].rotate(alpha);
- }
- if (isEquals()) {
- printf("2");
- }
- else {
- printf("3");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement