QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#433569#8676. Three Kinds of Dice369PaiTL 7ms8840kbC++172.5kb2024-06-08 12:46:522024-06-08 12:46:53

Judging History

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

  • [2024-06-08 12:46:53]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:8840kb
  • [2024-06-08 12:46:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5 , T = N * 4;
const double EPS = 1e-10;
int n , m , a[N] , b[N];
int tot , c[T] , v[T];
double f[T] , g[T];
double S(int n , int *a , int m , int *b)
{
	double ans = 0;
	sort(a + 1 , a + n + 1);
	sort(b + 1 , b + m + 1);
	for(int i = 1 , j = 1 , k = 1 ; i <= n ; i++)
	{
		while(j <= m && a[i] > b[j])j++;
		while(k <= m && a[i] >= b[k])k++;
		ans += j - 1 + (k - j) * 0.5;
	}
	return ans / n / m;
}
bool Check(double k)
{
	double mn = 1e18 , mx = 0;
	for(int i = 1 ; i <= tot ; i++)
	{
		double a = f[i] , b = g[i] - k;
		if(a >= 0 && b <= 0)
			return 1;
		if(a < 0 && b < 0)mn = min(mn , a / b);
		if(a > 0 && b > 0)mx = max(mx , a / b);
	}
	return mn <= mx;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0) , cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; i++)cin >> a[i];
	cin >> m;
	for(int i = 1 ; i <= m ; i++)cin >> b[i];
	if(S(n , a , m , b) <= 0.5)
		swap(a , b) , swap(n , m);
	memcpy(c , a , sizeof(int) * (n + 1));
	memcpy(c + n + 1 , b + 1 , sizeof(int) * m);
	sort(c + 1 , c + n + m + 1);
	for(int i = 1 ; i <= n + m ; i++)
	{
		if(c[i] == c[i - 1])continue ;
		else 
		{
			if(c[i - 1] + 1 < c[i])
				v[++tot] = c[i - 1] + 1;
			v[++tot] = c[i];
		}
	}
	v[++tot] = 1e9 + 5;
	sort(v + 1 , v + tot + 1);
	for(int i = 1 ; i <= n ; i++)
		a[i] = lower_bound(v + 1 , v + tot + 1 , a[i]) - v;
	for(int i = 1 ; i <= m ; i++)
		b[i] = lower_bound(v + 1 , v + tot + 1 , b[i]) - v;
	for(int i = 1 ; i <= tot ; i++)
	{
		for(int j = 1 ; j <= n ; j++)
			f[i] += (i > a[j]) + 0.5 * (i == a[j]);
		f[i] = f[i] / n - 0.5;
		for(int j = 1 ; j <= m ; j++)
			g[i] += (i > b[j]) + 0.5 * (i == b[j]);
		g[i] /= m;		
	}
	double l = 0 , r = 1;
	while(fabs(l - r) > EPS)
	{
		double mid = (l + r) / 2;
		if(Check(mid))r = mid;
		else l = mid;
	}
	cout << setprecision(9) << fixed << l << " ";
	// for(int i = 1 ; i <= n ; i++)cerr << a[i] << " \n"[i == n];
	// for(int i = 1 ; i <= m ; i++)cerr << b[i] << " \n"[i == m];
	for(int i = 1 ; i <= tot ; i++)
	{
		f[i] = g[i] = 0;
		for(int j = 1 ; j <= m ; j++)
			f[i] += (i < b[j]) + 0.5 * (i == b[j]);
		f[i] = f[i] / m - 0.5;
		for(int j = 1 ; j <= n ; j++)
			g[i] += (i < a[j]) + 0.5 * (i == a[j]);
		g[i] /= n;		
		// cerr << i << ":" << f[i] << " " << g[i] << "\n";
	}
	l = 0 , r = 1;
	while(fabs(l - r) > EPS)
	{
		double mid = (l + r) / 2;
		if(Check(mid))r = mid;
		else l = mid;
	}
	cout << setprecision(9) << fixed << 1.0 - l << "\n";
	return 0;
}

详细

Test #1:

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

input:

3 2 4 9
3 1 6 8

output:

0.291666667 0.750000000

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 8744kb

input:

3 1 6 8
6 2 2 4 4 9 9

output:

0.291666667 0.750000000

result:

ok 2 numbers

Test #3:

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

input:

1 1
1 2

output:

0.750000000 0.000000000

result:

ok 2 numbers

Test #4:

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

input:

5 2 2 2 3 3
6 5 5 6 6 6 7

output:

0.500000000 0.500000000

result:

ok 2 numbers

Test #5:

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

input:

6 2 2 7 7 9 9
6 3 3 5 5 10 10

output:

0.250000000 0.750000000

result:

ok 2 numbers

Test #6:

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

input:

11 12 11 15 9 3 8 18 4 17 13 9
11 8 18 5 15 12 5 11 11 11 3 8

output:

0.473684211 0.525000000

result:

ok 2 numbers

Test #7:

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

input:

20 17 18 29 37 5 15 5 9 37 34 12 38 26 29 2 40 23 20 4 12
23 22 2 24 33 6 19 15 31 1 18 30 11 40 13 2 19 5 39 37 22 9 31 26

output:

0.440503432 0.554166667

result:

ok 2 numbers

Test #8:

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

input:

40 52 22 29 52 44 3 69 45 40 73 66 51 2 21 20 51 49 34 72 64 69 68 56 4 6 39 29 18 43 6 56 15 22 31 25 78 59 58 40 66
46 52 24 40 12 56 7 4 29 12 26 45 39 27 47 55 45 17 74 28 12 75 77 77 73 41 21 20 23 55 13 58 21 43 11 22 2 67 18 49 56 15 26 25 35 20 61

output:

0.433971447 0.565224359

result:

ok 2 numbers

Test #9:

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

input:

76 54 80 5 41 10 124 87 45 67 42 118 33 128 118 21 40 41 3 18 69 131 113 121 106 99 72 108 85 101 108 72 27 13 45 133 137 4 62 30 111 71 39 31 120 79 91 30 58 43 6 60 65 83 83 42 83 26 108 20 133 24 8 125 138 100 21 103 81 45 102 76 44 118 109 18 67
81 4 15 26 65 110 48 126 39 128 82 1 43 134 18 69 ...

output:

0.421188630 0.573711063

result:

ok 2 numbers

Test #10:

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

input:

96 11 1 23 7 6 41 8 11 40 5 24 32 40 40 24 24 24 23 17 21 27 21 21 42 1 29 15 45 24 44 50 1 34 11 7 1 12 45 15 3 14 9 25 5 5 20 31 1 41 44 7 27 28 11 24 37 50 7 7 48 1 22 4 5 40 32 33 32 18 18 26 49 28 34 42 29 15 18 4 42 12 21 17 10 47 2 44 40 8 15 7 44 25 5 13 19
88 16 30 20 24 2 26 39 28 1 16 10 ...

output:

0.481854839 0.518595041

result:

ok 2 numbers

Test #11:

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

input:

208 31 110 162 24 386 12 262 283 384 392 361 168 58 129 155 45 36 70 2 127 296 380 188 125 148 77 117 272 219 38 79 322 70 91 115 273 228 375 398 353 277 307 258 60 42 60 298 109 60 158 192 159 29 165 103 51 304 313 392 113 62 149 203 152 3 373 206 144 136 214 151 348 287 181 202 367 67 138 388 93 3...

output:

0.495587799 0.504427083

result:

ok 2 numbers

Test #12:

score: 0
Accepted
time: 7ms
memory: 8784kb

input:

1170 1311 1924 962 906 1767 1811 1941 1956 1311 364 371 1825 1155 918 1625 1882 1082 198 889 924 1830 244 589 1639 296 1326 1663 379 1479 1369 729 1698 870 1845 217 888 754 858 966 1887 61 1801 1002 1185 1848 610 1914 1742 409 648 781 445 1217 96 1639 1681 1028 923 123 1234 909 569 747 1182 1538 368...

output:

0.485542699 0.514105003

result:

ok 2 numbers

Test #13:

score: -100
Time Limit Exceeded

input:

22713 21796 19194 13993 27763 16658 14855 3720 21919 4029 27311 21879 4981 25538 24982 5230 7339 4299 26976 30753 39183 38686 25483 3489 12855 28134 34477 25105 39953 31801 23937 31229 26076 32962 33965 6078 33306 15915 21622 3643 29726 2542 27764 4554 17811 17329 10576 26448 24416 30696 3230 3730 1...

output:


result: