Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <string>
- #include <set>
- #include <cstdio>
- #include <iomanip>
- #include <map>
- #include <stdio.h>
- #include <math.h>
- #include <queue>
- #include <random>
- #define and &&
- #define or ||
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define PI acos(-1.0)
- using namespace std;
- const long long inf = 1e10;
- const long long m = 1e9 + 7;
- const long double e = 0.0000001;
- int gcd(int a, int b) { return b ? a : gcd(b, a % b); }
- int toNum(char s) {
- return s - 'a';
- }
- double S(int x1, int y1, int x2, int y2) {
- return abs(x1 * y2 - y1 * x2) / 2.0;
- }
- int f(double a, double b, double c, double x, double y) {
- double k = a * x + b * y + c;
- if (k > 0)
- return 1;
- else if (k < 0)
- return -1;
- else if (k == 0)
- return 0;
- }
- bool isCrossing(double x1, double y1, double x2, double y2, double x11, double y11, double x22, double y22)
- {
- double a1 = y2 - y1;
- double b1 = -(x2 - x1);
- double c1 = -x1 * (y2 - y1) + y1 * (x2 - x1);
- double a2 = y22 - y11;
- double b2 = -(x22 - x11);
- double c2 = -x11 * (y22 - y11) + y11 * (x22 - x11);
- double pos1 = f(a1, b1, c1, x11, y11);
- double pos2 = f(a1, b1, c1, x22, y22);
- double pos3 = f(a2, b2, c2, x1, y1);
- double pos4 = f(a2, b2, c2, x2, y2);
- if (!((x1 == x2 and y1 == y2) or (x11 == x22 and y11 == y22))) {
- if (!(c2 * a1 == a2 * c1 and b1 * a2 == b2 * a1 and c1 * b2 == c2 * b1)) {
- if (pos1 != pos2 and pos3 != pos4) {
- return true;
- }
- else {
- return false;
- }
- }
- else {
- if (x1 == x2 and x2 == x11 and x11 == x22) {
- if ((min(y1, y2) <= y11 and y11 <= max(y1, y2)) or (min(y1, y2) <= x22 and y22 <= max(y1, y2))) {
- return true;
- }
- else {
- return false;
- }
- }
- else if ((min(x1, x2) <= x11 and x11 <= max(x1, x2)) or (min(x1, x2) <= x22 and x22 <= max(x1, x2))) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- else {
- if (x1 == x2 and y1 == y2) {
- if (f(a2, b2, c2, x1, y1) == 0) {
- return true;
- }
- else {
- return false;
- }
- }
- else if (x11 == x22 and y11 == y22) {
- if (f(a1, b1, c1, x11, y11) == 0) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- }
- double len(vector<double>gg) {
- return pow((gg[0] * gg[0] + gg[1] * gg[1]), 0.5);
- }
- bool isRight(vector<double>first, vector<double>second) {
- double ans = first[0] * second[0] + first[1] * second[1];
- if (abs(ans) < e)
- return true;
- else
- return false;
- }
- double ax, bx, cx, dx, ay, by, cy, dy;
- vector <double> ab(2);
- vector <double> ac(2);
- vector <double> dc(2);
- vector <double> db(2);
- void input() {
- cin >> ax >> ay;
- cin >> bx >> by;
- cin >> dx >> dy;
- cin >> cx >> cy;
- ab[0] = bx - ax;
- ab[1] = by - ay;
- ac[0] = cx - ax;
- ac[1] = cy - ay;
- dc[0] = cx - dx;
- dc[1] = cy - dy;
- db[0] = bx - dx;
- db[1] = by - dy;
- }
- void solve() {
- if ((isCrossing(ax, ay, bx, by, cx, cy, dx, dy) || isCrossing(ax, ay, cx, cy, bx, by, dx, dy)))
- cout << "self-intersecting polyline";
- else if (!(isCrossing(ax, ay, dx, dy, bx, by, cx, cy)))
- cout << "non-convex polygon";
- else if (abs(len(ab) - len(dc)) < e && abs(len(ab) - len(db)) < e && abs(len(ac) - len(dc)) < e && isRight(ab, ac) && isRight(dc, db))
- cout << "square";
- else if (abs(len(ab) - len(dc)) < e && abs(len(ab) - len(db)) < e && abs(len(ac) - len(dc)) < e)
- cout << "rhombus";
- else if (isRight(ab, ac) && isRight(dc, db))
- cout << "rectangle" << "\n";
- else if (abs(ab[0] * dc[1] - ab[1] * dc[0]) < e && abs(ac[0] * db[1] - ac[1] * db[0]) < e)
- cout << "parallelogram";
- else if (abs(ab[0] * dc[1] - ab[1] * dc[0]) < e || abs(ac[0] * db[1] - ac[1] * db[0]) < e)
- cout << "trapezoid";
- else
- cout << "convex polygon";
- }
- int main() {
- IOS;
- input();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement