QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#451147#6831. Known as the Fruit BrotherPetroTarnavskyi#Compile Error//C++204.8kb2024-06-22 21:33:342024-06-22 21:33:34

Judging History

你现在查看的是最新测评结果

  • [2024-06-22 21:33:34]
  • 评测
  • [2024-06-22 21:33:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long double db;

const db EPS = 1e-9;
const db INF = 1e9;

template<typename T>
void updMin(T& a, T b)
{
	a = min(a, b);
}

struct Pt
{
	db x, y;
	Pt operator+(const Pt& p) const
	{
		return {x + p.x, y + p.y};
	}
	Pt operator-(const Pt& p) const
	{
		return {x - p.x, y - p.y};
	}
	Pt operator*(db d) const
	{
		return {x * d, y * d};
	}
	Pt operator/(db d) const
	{
		return {x / d, y / d};
	}
};

db sq(const Pt& p)
{
	return p.x * p.x + p.y * p.y;
}

db abs(const Pt& p)
{
	return sqrt(sq(p));
}

int sgn(db x)
{
	return (EPS < x) - (x < -EPS);
}

Pt perp(const Pt& p)
{
	return {-p.y, p.x};
}

db dot(const Pt& p, const Pt& q)
{
	return p.x * q.x + p.y * q.y;
}

db cross(const Pt& p, const Pt& q)
{
	return p.x * q.y - p.y * q.x;
}

db orient(const Pt& p, const Pt& q, const Pt& r)
{
	return cross(q - p, r - p) / abs(q - p);
}

ostream& operator<<(ostream& os, const Pt& p)
{
	return os << "(" << p.x << "," << p.y << ")";
}

struct Line
{
	Pt n;
	db c;
	Line(const Pt& p, const Pt& q):
		n(perp(q - p)), c(-dot(n, p)) {}
	db side(const Pt& p) const
	{
		return dot(n, p) + c;
	}
	db sqDist(const Pt& p) const
	{
		return side(p) * side(p) / (db)sq(n);
	}
	Pt proj(const Pt& p) const
	{
		return p - n * side(p) / sq(n);
	}
};

bool inDisk(const Pt& a, const Pt& b, const Pt& p)
{
	return sgn(dot(a - p, b - p)) <= 0;
}

bool onSegment(const Pt& a, const Pt& b, const Pt& p)
{
	return sgn(orient(a, b, p)) == 0 && inDisk(a, b, p);
}

bool properInter(const Pt& a, const Pt& b, const Pt& c, const Pt& d)
{
	db oa = orient(c, d, a);
	db ob = orient(c, d, b);
	db oc = orient(a, b, c);
	db od = orient(a, b, d);
	return sgn(oa) * sgn(ob) == -1 && sgn(oc) * sgn(od) == -1;
}

vector<Pt> circleLine(const Pt& o, db r, const Line& l)
{
	db h2 = r * r - l.sqDist(o);
	if (sgn(h2) == -1)
		return {};
	Pt p = l.proj(o);
	if (sgn(h2) == 0)
		return {p};
	Pt h = perp(l.n) * sqrt(h2) / abs(l.n);
	return {p - h, p + h};
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int n, m, r;
	cin >> n >> m >> r;
	vector<Pt> vertices;
	FOR(i, 0, n)
	{
		db x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		vertices.PB({x1, y1});
		vertices.PB({x2, y1});
		vertices.PB({x2, y2});
		vertices.PB({x1, y2});
	}
	FOR(i, 0, m)
	{
		db x, y;
		cin >> x >> y;
		vertices.PB({x, y});
	}
	db xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	vertices.PB({xs, ys});
	vertices.PB({xt, yt});
	int k = SZ(vertices);
	vector dist(k, vector<db>(k, INF));
	auto check = [&](const Pt& p1, const Pt& p2) -> bool
	{
		bool ok = true;
		FOR(l, 0, n)
		{
			FOR(p, 0, 4)
			{
				Pt q1 = vertices[4 * l + p], q2 = vertices[4 * l + (p + 1) % 4];
				ok &= !properInter(p1, p2, q1, q2);
			}
			ok &= !(onSegment(p1, p2, vertices[4 * l]) && onSegment(p1, p2, vertices[4 * l + 2]));
			ok &= !(onSegment(p1, p2, vertices[4 * l + 1]) && onSegment(p1, p2, vertices[4 * l + 3]));
		}
		return ok;
	};
	auto checkPoint = [&](const Pt& pt) -> bool
	{
		FOR(l, 0, n)
		{
			bool inside = true;
			FOR(p, 0, 4)
			{
				Pt q1 = vertices[4 * l + p], q2 = vertices[4 * l + (p + 1) % 4];
				inside &= sgn(orient(q1, q2, pt)) >= 0;
			}
			if (inside)
				return false;
		}
		return true;
	};
	FOR(i, 0, k)
	{
		FOR(j, 0, k)
		{
			if (i == j)
			{
				dist[i][j] = 0;
				continue;
			}
			Pt p1 = vertices[i], p2 = vertices[j];
			bool blast = 4 * n <= i && i < 4 * n + m;
			if (check(p1, p2))
			{
				db d = abs(p2 - p1);
				if (blast)
					d = max(0.0, d - r);
				updMin(dist[i][j], d);
			}
			if (blast)
			{
				FOR(l, 0, n)
				{
					FOR(p, 0, 4)
					{
						Pt q1 = vertices[4 * l + p], q2 = vertices[4 * l + (p + 1) % 4];
						Line q12(q1, q2);
						vector<Pt> vec = circleLine(p1, r, q12);
						for (const Pt& pt : vec)
						{
							if (onSegment(q1, q2, pt) && check(pt, p2))
							{
								updMin(dist[i][j], abs(p2 - pt));
							}
						}
					}
				}
				if (r < abs(p2 - p1) - EPS)
				{
					Pt pt = p1 + (p2 - p1) / abs(p2 - p1) * r;
					cerr << p1 << " " << p2 << " " << pt << endl;
					if (check(pt, p2) && checkPoint(pt))
					{
						updMin(dist[i][j], abs(p2 - pt));
					}
				}
				else
				{
					dist[i][j] = 0;
				}
			}
		}
	}
	FOR(kk, 0, k)
		FOR(i, 0, k)
			FOR(j, 0, k)
				updMin(dist[i][j], dist[i][kk] + dist[kk][j]);
	cout << dist[k - 2][k - 1] << "\n";
	return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:214:48: error: no matching function for call to ‘max(double, db)’
  214 |                                         d = max(0.0, d - r);
      |                                             ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:214:48: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘db’ {aka ‘long double’})
  214 |                                         d = max(0.0, d - r);
      |                                             ~~~^~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:214:48: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘db’ {aka ‘long double’})
  214 |                                         d = max(0.0, d - r);
      |                                             ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:214:48: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
  214 |                                         d = max(0.0, d - r);
      |                                             ~~~^~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answer.code:214:48: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
  214 |                                         d = max(0.0, d - r);
      |                                             ~~~^~~~~~~~~~~~