Блог пользователя Krsna_Consciousness

Автор Krsna_Consciousness, история, 3 года назад, По-английски

I have been trying to understand solution code of this problem given by Isanchez_Aguilar. I am having trouble in understanding function inline Vector operator+ & — both. I am also not able to get what "Vector():x(0), y(0) {}" &"Vector(Double _x, Double _y):x(_x), y(_y) {}" are supposed to mean.

Isanchez_Aguilar's solution code is below and you can also use this link:https://github.com/isanchez-aguilar/UVa-Solutions/blob/master/10242%20-%20Fourth%20Point%20!!.cpp

#include <bits/stdc++.h>

using namespace std;

typedef double Double;

const Double EPS = 1e-3;

inline Double isEqual(Double a, Double b) { return fabs(a &mdash; b) < EPS; }

class Vector
{
public:
	Double x;
	Double y;

	Vector():x(0), y(0) {}

	Vector(Double _x, Double _y):x(_x), y(_y) {}

	inline bool operator==(const Vector& a) const { return isEqual(x, a.x) and isEqual(y, a.y);	}

	inline Vector operator+(const Vector& a)
	{
		Vector b;
		b.x = x + a.x;
		b.y = y + a.y;
		
		return b;
	}

	inline Vector operator-(const Vector& a)
	{
		Vector b;
		b.x = x - a.x;
		b.y = y - a.y;
		
		return b;
	}
};

Vector points[4];

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cout.precision(3);
	cout.setf(ios::fixed);

	while (cin >> points[0].x >> points[0].y)
	{
		for (int i = 1; i < 4; ++i)
			cin >> points[i].x >> points[i].y;

		int a = 1;
		int b = 0;
		int c = 2;

		if (points[0] == points[2])
		{
			a = 0;
			b = 1;
			c = 3;
		}
		else if (points[0] == points[3])
		{
			a = 0;
			b = 1;
			c = 2;

		}
		else if (points[1] == points[2])
			c = 3;

		Vector p = points[c] + points[b] - points[a];

		cout << p.x << " " << p.y << "\n";
	}

	return 0;
}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

Автор Krsna_Consciousness, история, 3 года назад, По-английски

would anyone please share some hints on how to solve this problem,so that i may eventually be able to solve it. The editorial for this problem is of one line(that also is a hint),hence i am not able to solve it?? here is the link to problem :https://codeforces.me/problemset/problem/261/E .

Полный текст и комментарии »

  • Проголосовать: нравится
  • -18
  • Проголосовать: не нравится