QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398737#2338. Beautiful BridgesBIXIANRE 1ms3692kbC++141.9kb2024-04-25 17:30:032024-04-25 17:30:03

Judging History

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

  • [2024-04-25 17:30:03]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3692kb
  • [2024-04-25 17:30:03]
  • 提交

answer

#include<iostream>
using namespace std;
int f[100];
int n, h, a, d,ans,w;
int s[100][2];
bool df(int a, int b)
{
	double midx = ((double)a + (double)b) / 2;
	double midy = h - ((double)b - (double)a) / 2;
	if (midy < f[a] || midy < f[b])
	{
		return 0;
	}
	double r = ((double)b - (double)a) / 2;
	for (int i = a; i <= b; i++)
	{
		if (f[i]>=0)
		{
			if ((f[i]>=midy)&&((midx - (double)i) * (midx - (double)i) + (midy - (double)f[i]) * (midy - (double)f[i]))>(r*r))
				return 0;
		}
	}
	return 1;
}
int vv = 0;
void dfs(int i)
{
	for (int j = i + 1; j <= ans; j++)
	{
		if ((df(s[i][0], s[j][0])))
		{
			s[i][1] = j;
			w += d * ((s[j][0] - s[i][0]) * (s[j][0] - s[i][0]))+a * (h - f[s[j][0]]);
			if (j == ans)
			{
				vv = 1;
				return;
			}
			dfs(j);
			if (vv)
				return;
			w -= d * ((s[j][0] - s[i][0]) * (s[j][0] - s[i][0]))+a * (h - f[s[j][0]]);
		}
	}
}
int main()
{
	cin >> n >> h >> a >> d;
	int max1 = 0,x,fr;
	for (int i = 1; i <= 99; i++)
		f[i] = -1;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		cin >> f[x];
		ans++;
		s[ans][0] = x;
		if (f[x] > max1)
			max1 = f[x];
	}
	w += a * (h - f[s[1][0]]);
	dfs(1);
	if (!vv)
		cout << "impossible";
	if(vv)
	{
		while (1)
		{
			int yy = 1;
			bool v = 1;
			while (yy != ans && s[yy][1] != ans)
			{
				if (df(s[yy][0], s[s[s[yy][1]][1]][0]))
				{
					int qw = h - f[s[s[yy][1]][0]];
					int qe = (s[s[s[yy][1]][1]][0] - s[yy][0]) * (s[s[s[yy][1]][1]][0] - s[yy][0]);
					int qe1 = (s[s[s[yy][1]][1]][0] - s[s[yy][1]][0]) * (s[s[s[yy][1]][1]][0] - s[s[yy][1]][0]);
					int qe2 = (s[s[yy][1]][0] - s[yy][0]) * ((s[s[yy][1]][0] - s[yy][0]));
					if (a * qw > d * (qe - qe1 - qe2))
					{
						v = 0;
						s[yy][1] = s[s[yy][1]][1];
						w -= a * qw - d * (qe - qe1 - qe2);
					}
				}
				yy = s[yy][1];
			}
			if (v)
				break;
		}
		cout << w;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 60 18 2
0 0
20 20
30 10
50 30
70 20

output:

6460

result:

ok single line: '6460'

Test #2:

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

input:

4 10 1 1
0 0
1 9
9 9
10 0

output:

impossible

result:

ok single line: 'impossible'

Test #3:

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

input:

2 1 1 1
0 0
2 0

output:

6

result:

ok single line: '6'

Test #4:

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

input:

2 1 1 1
0 0
3 0

output:

impossible

result:

ok single line: 'impossible'

Test #5:

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

input:

4 5 100 1
0 0
1 3
9 3
10 0

output:

1100

result:

ok single line: '1100'

Test #6:

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

input:

4 5 1 100
0 0
1 3
9 3
10 0

output:

10010

result:

ok single line: '10010'

Test #7:

score: -100
Runtime Error

input:

2 100000 10000 10000
0 0
100000 0

output:


result: