比赛链接
官方题解
Problem A. Digit Sum 2
考虑如何用最小的数得到某个数位和 S S S ,显然是将最低的若干位设为 9 9 9 。
因此,我们只需要考虑形如 x 999 … 9 x999\dots9 x999…9 的数,找到 N N N 以内最大的这样的数即可。
时间复杂度 O ( L o g N ) O(LogN) O(LogN) 。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
template <typename T> void write(T x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
ll n, t; int ans;
int main() {
read(n);
while (10 * t + 9 <= n) {
t = 10 * t + 9;
ans += 9;
}
n -= t;
while (n >= t + 1) n -= t + 1, ans++;
writeln(ans);
return 0;
}
Problem B. Holes
本质上,我们需要计算的是各个点对应的 V 图区域的面积比圆形区域面积。
由于随机范围较大,不妨认为所选点距离原点足够远,那么显然,对应的 V 图区域仅限于 [ − 1 0 6 , 1 0 6 ] × [ − 1 0 6 , 1 0 6 ] [-10^6,10^6]\times[-10^6,10^6] [−106,106]×[−106,106] 内的点被选中的概率几乎为 0 0 0 。
我们只需要考虑所给点集凸包上的顶点即可,每个顶点被选中的概率即为其与相邻顶点连线中垂线的夹角占 2 π 2\pi 2π 的比例。
时间复杂度 O ( N L o g N ) O(NLogN) O(NLogN) 。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const double pi = acos(-1);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
template <typename T> void write(T x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
struct point {int x, y; };
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, int b) {return (point) {a.x * b, a.y * b}; }
long long operator * (point a, point b) {return 1ll * a.x * b.y - 1ll * a.y * b.x; }
bool operator < (point a, point b) {
if (a.y == b.y) return a.x < b.x;
else return a.y < b.y;
}
long long dist(point a) {return 1ll * a.x * a.x + 1ll * a.y * a.y; }
int n, m, q; map <point, double> mp;
point a[MAXN], b[MAXN], fp;
bool cmp(point a, point b) {
long long tmp = (a - fp) * (b - fp);
if (tmp == 0) return dist(a - fp) < dist(b - fp);
else return tmp > 0;
}
double PolarAngle(point x) {
return atan2(x.y, x.x);
}
int main() {
read(n);
for (int i = 1; i <= n; i++) {
read(a[i].x), read(a[i].y);
b[i] = a[i];
}
for (int i = 2; i <= n; i++)
if (a[i] < a[1]) swap(a[i], a[1]);
fp = a[1];
sort(a + 2, a + n + 1, cmp);
a[n + 1] = a[1];
int top = 1;
for (int i = 2; i <= n + 1; i++) {
while (top >= 2 + (i == n + 1) && (a[top] - a[top - 1]) * (a[i] - a[top - 1]) <= 0) top--;
a[++top] = a[i];
}
a[0] = a[top - 1];
for (int i = 1; i <= top - 1; i++) {
double res = PolarAngle(a[i + 1] - a[i]) - PolarAngle(a[i] - a[i - 1]);
if (res < 0) res += 2 * pi;
mp[a[i]] = res / (2 * pi);
}
for (int i = 1; i <= n; i++)
printf("%.10lf\n", mp[b[i]]);
return 0;
}
Problem C. Tiling
首先可以通过面积来对可行性进行考虑,记网格面积减瓷砖面积为 d d d ,若 d < 0 d<0 d<0 ,答案显然为 NO 。
考虑 N , M N,M N,M 均为偶数的情况,我们可以将网格分成若干 2 × 2 2\times2 2×2 的小方格,在每一个小方格内放入相同类型的瓷砖,不难证明对于所有答案为 YES 的输入,该算法都可以正确地进行构造。
考虑 N , M N,M N,M 中存在偶数的情况,不妨令 N N N 为偶数, M M M 为奇数,则每一行至多放置 M −