QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#367521#7846. Glacier TravelsquishybananaWA 1ms3932kbC++233.9kb2024-03-26 04:29:062024-03-26 04:29:07

Judging History

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

  • [2024-03-26 04:29:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3932kb
  • [2024-03-26 04:29:06]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
using ld = double;
using pld = pair<ld,ld>;
using pii = pair<int, int>;

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")"; }
};
template<class P>
vector<P> circleLine(P c, double r, P a, P b) {
	P ab = b - a, p = a + ab * (c-a).dot(ab) / ab.dist2();
	double s = a.cross(b, c), h2 = r*r - s*s / ab.dist2();
	if (h2 < 0) return {};
	if (h2 == 0) return {p};
	P h = ab.unit() * sqrt(h2);
	return {p - h, p + h};
}

double gss(double a, double b, function<double(double)> f) {
	double r = (sqrt(5)-1)/2, eps = 1e-6;
	double x1 = b - r*(b-a), x2 = a + r*(b-a);
	double f1 = f(x1), f2 = f(x2);
	while (b-a > eps) {
		if (f1 < f2) { //change to > to find maximum
			b = x2; x2 = x1; f2 = f1;
			x1 = b - r*(b-a); f1 = f(x1);
		} else {
			a = x1; x1 = x2; f1 = f2;
			x2 = a + r*(b-a); f2 = f(x2);
		}
	}
	return a;
}

ld s;

int n;
vector<Point<ld>> p;
int main() {
	cin >> s;
	cin >> n;
	p.resize(n);
	for (auto &[i, j] : p) {
		int x, y ; cin >> x >> y;
		i = x;j = y;
	}
	for (int i = n-1; i >= 0; i--) {
		p[i] = p[i] - p[0];
	}


	Point<ld> me = p[0], partner;
	bool started = false;
	int i = 0, j = -1;
	ld ans = 1e9;
	bool bum = 0;
	while (i < n-1) {
		if (started) {
			ans = min((me-partner).dist(), ans);
		}
		int stepType = -1;

		ld nextT = 1e9;
		if (i < n-1) {
			ld o = (me-p[i+1]).dist2();
			if (o < nextT) {
				stepType = 0;
				nextT = o;
			}
		}

		if (started) {
			ld o = (partner - p[j+1]).dist2();
			if (o < nextT) {
				nextT = o;
				stepType = 1;
			}
			auto partnerDir = (p[j+1]-p[j]).unit();
			auto dir = (p[i+1]-p[i]).unit();

			if (!bum) {
				function<double(double)> dis = [&](double t) ->double {
					return (me + dir*t - partner - partnerDir*t).dist2();
				};
				// weird shit
				o = gss(0, nextT, dis);
				o = o*o;
				if (o < nextT && o > 0) {
					nextT = o;
					stepType = 3;
				}
			}
		}
		else {
			auto a = circleLine(Point<ld>{0, 0}, s, p[i], p[i+1]);
			if (a.size()) {
				ld o = (me-a[0]).dist2();
				if (o < nextT) {
					nextT = o;
					stepType = 2;
				}
			}
		}
		nextT = sqrt(nextT);
		if (started) {
			auto partnerDir = (p[j+1]-p[j]).unit();
			partner = partner+partnerDir*nextT;
		}
		auto dir = (p[i+1]-p[i]).unit();
		me = me+dir*nextT;
		if (stepType == 0) {
			i++;
			bum = false;
		}
		else if (stepType == 1) {
			j++;
			bum = false;
		}
		else if (stepType == 2) {
			j = 0;
			started = true;
			partner = p[0];
			bum = false;
		}
		else if (stepType == 3) {
			bum = true;
		}
	}

	cout << setprecision(20) << fixed << ans << endl;

}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3820kb

input:

5
4
20 0
10 0
10 10
0 10

output:

3.53553390593274441400

result:

ok found '3.53553', expected '3.53553', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

0.99999999994729193986

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

2.29359576035641454794

result:

ok found '2.29360', expected '2.29360', error '0.00000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

10
40
17 18
12 -5
12 -16
-10 16
7 -15
18 -18
19 15
-19 1
-18 11
-8 -12
-17 -12
5 -12
-15 -8
-10 -10
-4 4
-2 -3
15 17
-2 -9
-13 7
-12 17
15 -3
-19 -14
6 6
14 -5
-10 -15
17 -16
-11 15
9 -6
10 8
19 -1
12 -6
-18 2
14 17
9 -7
-8 -3
7 11
-12 -14
-19 4
-1 15
-17 16

output:

0.00000099601761860413

result:

ok found '0.00000', expected '0.00000', error '0.00000'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3724kb

input:

10
40
10 11
11 15
6 -16
-18 4
10 10
-10 16
-17 11
2 6
-6 -9
17 -7
-7 -5
10 -18
-9 9
-14 10
19 -3
-14 -3
15 -5
-3 16
-10 14
-9 -12
10 -18
10 -4
-9 -11
11 -2
9 2
12 15
2 -17
-8 -16
19 7
-19 -2
-17 7
16 -9
6 -6
8 -18
15 9
17 2
-19 12
-15 -9
1 -15
19 -12

output:

0.34451634495721406015

result:

wrong answer 1st numbers differ - expected: '0.34421', found: '0.34452', error = '0.00030'