QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461128#7846. Glacier TravelLingKerAC ✓22ms4048kbC++203.6kb2024-07-02 16:13:492024-07-02 16:13:49

Judging History

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

  • [2024-07-02 16:13:49]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:4048kb
  • [2024-07-02 16:13:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
const double eps=1e-3;
using namespace std;
typedef long long LL;
#define int long 
#define double long double
template <typename T>
inline void read(T &x)
{
    T f = 1;
    x = 0;
    char ch = getchar();
    while (0 == isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (0 != isdigit(ch))
        x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
    x *= f;
}
template <typename T>
inline void write(T x)
{
    if (x < 0)
    {
        x = ~(x - 1);
        putchar('-');
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
int dcmp(double x)
{
	if(fabs(x) < eps) return 0;
	else return x < 0 ? -1 : 1;
}
struct point
{
	double x, y;
	point (double _x = 0, double _y = 0) : x(_x) , y(_y){}
	point rot(const double rad) const { return {x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)}; }
};
point operator + (point a , point b) {return point(a.x + b.x,a.y + b.y);}
point operator - (point a , point b) {return point(a.x - b.x , a.y - b.y);}
point operator * (point a , double t) {return point(a.x*t,a.y*t);}
point operator / (point a , double t) {return point(a.x/t,a.y/t);}
bool operator == (const point &a , const point b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;}
bool operator <(const point& A,const point& B){
	if(A.x == B.x) return A.y < B.y;
	return A.x < B.x;
}
double cross (point a , point b) {return a.x * b.y - b.x * a.y;}
double dot (point a , point b) {return a.x * b.x + a.y * b.y;}
double len(point v) {return sqrt(dot(v,v));}
struct Line
{
	point p,v;
	Line(){}//reserve需要
	Line(point _p , point _v) : p(_v) , v(_p){}
	point get_point_in_line(double t)
	{
		return v + (p - v) * t;
	}
	double dis(const point &a) const {return abs(cross(v - p , a - p)) / len(v - p); }
};

//思路:先找到大于s的线段,标记为a线段,第一个线段标记为b线段
//af,bf表示对于这个线段来说,从这个线段起点到af/bf的距离

void solve()
{
	double s;
	int n;
	cin >> s >> n;
	vector<point> p(n);
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> p[i].x >> p[i].y;
	}
	auto res = [&](int st , double offset)
	{
		return len(p[st + 1] - p[st]) - offset;
	};
	auto getp = [&](int st , double offset)
	{
		double lenth = len(p[st + 1] - p[st]);
		return p[st] + (p[st + 1] - p[st]) * offset/lenth;
	};
	int as = 0 , bs = 0;//表示所处与第几个条线段
	double af = 0.0L , bf = 0.0L;//表示最后一段线段所走的长度
	while(as < n - 1)
	{
		double r = res(as,af);
		if(s > r)
		{
			s -= r;
			as++;
			af = 0;
		}else{
			af = s;
			break;
		}
	}

	double ans = 1e18;
	while(as < n - 1)
	{
		double ar = res(as,af),br = res(bs,bf);//a能走最远和b能走的最远
		double l = 0 , r = min(ar,br);
		while(r - l > 1e-8)
		{
			double m1 = (l + l + r)/3 , m2 = (l + r + r)/3;
			point a1 = getp(as,af+m1),a2 = getp(as,af+m2);
			point b1 = getp(bs,bf+m1),b2 = getp(bs,bf+m2);
			if(len(a1-b1) < len(a2-b2)) r = m2;
			else l = m1;
		}
		point pa = getp(as,af+l) , pb = getp(bs,bf+l);
		ans = min(ans,len(pa-pb));
		if(ar < br)
		{
			bf += ar;
			as ++;
			af = 0;
		}else{
			af += br;
			bs ++;
			bf = 0;
		}
	}
	cout << fixed << setprecision(10) << ans << char(10);
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while(t --)
	{	
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

5
4
20 0
10 0
10 10
0 10

output:

3.5355339059

result:

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

Test #2:

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

input:

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

output:

0.9999999999

result:

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

Test #3:

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

input:

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

output:

2.2935957604

result:

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

Test #4:

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

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.0000000070

result:

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

Test #5:

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

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.3442144373

result:

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

Test #6:

score: 0
Accepted
time: 22ms
memory: 4044kb

input:

1000
4000
-720538 -681604
667325 347504
-911397 -962007
-264075 -858319
49605 149209
964851 361021
-397274 28661
-460607 -273701
104862 -136807
-803899 -693703
-974 -337735
323678 -209811
-745617 -358684
-984333 603546
722843 -444579
701511 -255784
-676477 -836480
998942 -227888
-502059 -438394
9641...

output:

0.0445047436

result:

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

Test #7:

score: 0
Accepted
time: 20ms
memory: 4048kb

input:

1000
4000
703 909
500 496
-214 628
914 -44
-330 -238
-1424 -1426
347 1420
332 -1417
877 1678
-1390 819
-921 525
121 -923
-851 -859
512 -151
765 -109
416 -1529
-269 667
475 -234
-708 300
1917 -1935
-909 1342
1141 -696
-272 1295
1908 -1124
-898 -1225
1608 630
-1937 1246
-255 1021
-1005 -1650
-1595 -39...

output:

0.0381857100

result:

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

Test #8:

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

input:

40
3
100 0
0 100
0 0

output:

15.3073372946

result:

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

Test #9:

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

input:

48.2842712475
4
-10 -10
10 10
-10 10
10 -10

output:

0.0000000077

result:

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