2020牛客暑期多校训练营(第一场)

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(xx2)ndx=01xn(1x)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(1x)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 =202π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+1202π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 =22n1102π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;
}

赛后总结:

《关于出题人说全都是弱智题但我啥都不会的那些事》

网络流还是差了点,要补补。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值