2020牛客暑期多校训练营(第一场)(2020.7.12)
开始堇业,把之前欠的债补上。
F、Infinite String Comparison
这题就是类似于观察一下性质。其实可以发现把长度最长的那个串拼成两倍,之后在这个范围内一定能比较出大小。画个图,把相同的拼一拼就行了。
如果到了两倍还没比较出大小就说明一定相等。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
string a, b;
while (cin >> a >> b)
{
int pos_a = 0, pos_b = 0, cnt = 0;
bool flag = 0;
while (cnt < max(a.length(), b.length()) * 2)
{
++cnt;
if (a[pos_a] == b[pos_b])
{
pos_a++; if (pos_a >= a.length()) pos_a -= a.length();
pos_b++; if (pos_b >= b.length()) pos_b -= b.length();
}
else
{
if (a[pos_a] > b[pos_b]) cout << '>' << endl;
else cout << '<' << endl;
flag = 1; break;
}
}
if (!flag) cout << '=' << endl;
}
return 0;
}
J、Easy Integration
这题就是考你会不会高数。
∫ 0 1 ( x − x 2 ) n d x = ∫ 0 1 x n ( 1 − x ) n d x \int_0^1(x-x^2)^ndx=\int_0^1x^n(1-x)^ndx ∫01(x−x2)ndx=∫01xn(1−x)ndx
观察形式,想到三角换元。令 x = s i n 2 t x=sin^2t x=sin2t
∫ 0 1 x n ( 1 − x ) n d x = ∫ 0 π 2 s i n 2 n t c o s 2 n t 2 s i n t c o s t d t \int_0^1x^n(1-x)^ndx=\int_0^{\pi\over2}sin^{2n}tcos^{2n}t2sintcostdt ∫01xn(1−x)ndx=∫02πsin2ntcos2nt2sintcostdt
稍微整理一下
= 2 ∫ 0 π 2 s i n 2 n + 1 t c o s 2 n + 1 t d t =2\int_0^{\pi\over2}sin^{2n+1}tcos^{2n+1}tdt =2∫02πsin2n+1tcos2n+1tdt
= 2 2 2 n + 1 ∫ 0 π 2 s i n 2 n + 1 2 t d t ={2\over{2^{2n+1}}}\int_0^{\pi\over2}sin^{2n+1}2tdt =22n+12∫02πsin2n+12tdt
= 1 2 2 n − 1 ∫ 0 π 2 s i n 2 n + 1 t d t ={1\over{2^{2n-1}}}\int_0^{\pi\over2}sin^{2n+1}tdt =22n−11∫02πsin2n+1tdt
之后就很显然了,直接上点火公式。但是直接点火公式不太好计算,这里建议写成一个关于 n n n的递推式。具体见代码。
预处理出答案, O ( 1 ) O(1) O(1)查询。
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAXN = 1e6 + 10;
typedef long long ll;
ll qpow(ll a, ll b)
{
ll ans = 1; a = a % MOD;
while (b)
{
if (b & 1) ans = (ans * a) % MOD;
b >>= 1; a = (a * a) % MOD;
}
return ans;
}
ll inv(ll a)
{
return qpow(a, MOD - 2);
}
int main()
{
ll p = 1, q = 1;
static ll ans[MAXN];
for (int i = 0; i <= 1e6; ++i)
{
p = (i + 1) * p % MOD;
q = 2 * (2 * i + 3) * q % MOD;
ans[i + 1] = (p * inv(q)) % MOD;
}
ll n;
while (~scanf("%lld", &n))
{
printf("%lld\n", ans[n]);
}
return 0;
}
赛后总结:
《关于出题人说全都是弱智题但我啥都不会的那些事》
网络流还是差了点,要补补。