- SleepingCup 的博客
-
Sleeping Cup #3 Editor
- @ 2026-3-1 22:56:44
A - Grammar quiz
'1': '624'
'2': $2^{19937}-1$
'3': C++26
'4': CF1812H
'5': shuffle(v.begin(),v.end(),default_random_engine(time(0)));
B - Not a median problem
对于 的数据,直接排序即可。
对于剩下 的数据,不难发现生成的数是 范围内的随机数,中位数一定在 附近,因此选出 附近的数排序即可。
#include <bits/stdc++.h>
using namespace std;
unsigned int n, x;
inline unsigned int get()
{
x ^= x << 7;
x ^= x >> 23;
x ^= x << 12;
return x;
}
unsigned int f[120012];
void first()
{
for (int i = 1; i <= n; i++)
f[i] = get();
sort(f + 1, f + n + 1);
cout << f[n / 2 + 1] << endl;
}
void second()
{
unsigned int l = (1ll << 31) - (1ll << 31) * 100000 / n - 1;
unsigned int r = (1ll << 31) + (1ll << 31) * 100000 / n;
unsigned int low = 0, med = 0, high = 0;
for (int i = 1; i <= n; i++)
{
unsigned int k = get();
if (k > r) high++;
if (k < l) low++;
if(k >= l && k <= r)
{
med++;
f[med] = k;
}
}
sort(f + 1, f + med + 1);
cout << f[n / 2 + 1 - low] << endl;
}
int main()
{
freopen("median.in", "r", stdin);
freopen("median.out", "w", stdout);
cin >> n >> x;
if (n <= 100001) first();
else second();
return 0;
}
C - Missing circle
圆心解法
- 在两个维度上取圆内的点坐标的平均值为圆心。
- 在两个维度上计算圆内的点坐标的极值,取中点为圆心。
- 在两个维度上切片,取圆内的点密度最大的坐标为圆心。
- 在两个维度上取到圆内所有点距离之和最小的坐标为圆心。
半径解法
- 取圆内的点距圆心的最大距离为半径。
- 计算圆内的点距圆心的平均距离,利用积分折算为半径。
- 计算圆内的点的密度,估计圆的面积,利用圆的面积公式折算为半径。
- 在两个维度上计算圆内的点坐标的极值,取极差为直径,然后折算为半径。
参考程序
// 圆心解法:解法 1
// 半径解法:解法 3
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("circle.in", "r", stdin);
freopen("circle.out", "w", stdout);
int n = 100000, r = 1000;
long long oc = 0;
long double xs = 0, ys = 0;
for (int i = 1; i <= n; i++)
{
long double x, y;
int z;
cin >> x >> y >> z;
if (z) oc++, xs += x, ys += y;
}
cout << fixed << setprecision(3);
cout << xs / oc << ' ' << ys / oc << endl;
cout << sqrtl(oc * 1.0 * r * r / n / acos(-1)) << endl;
return 0;
}