2020牛客暑期多校训练营(第一场)题解F、J

F Infinite String Comparision

题目传送门

Infinite String Comparision

思路

直接跑两次最长的那个字符串即可判断大小关系

代码

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const double pi = acos(-1.0);
#define INF 0x3f3f3f3f
// #define TDS_ACM_LOCAL
string a, b;
int mx, flag, len1, len2;
void solve(){
    while(cin>>a>>b){
        len1=a.length(), len2=b.length();
        mx=max(len1, len2);
        flag=0;
        for(int i=0; i<2*mx; i++){
            if(a[i%len1]>b[i%len2])   {flag=1; break;}
            else if(a[i%len1]<b[i%len2])  {flag=2; break;}
        }
        if(flag==0) cout<<"="<<endl;
        else if(flag==1)    cout<<">"<<endl;
        else if(flag==2)    cout<<"<"<<endl;
    }
    return ;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
    freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
    freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
    solve();
    return 0;
}

J Easy Integration

题目传送门

Easy Integration

思路

由:

∫ 0 1 ​ ( x − x 2 ) n d x ∫^1_0​ (x−x^2)^ndx 01(xx2)ndx

可推出:

∫ 0 1 ​ x n ( 1 − x ) n d x ∫^1_0​ x^n(1−x)^ndx 01xn(1x)ndx

再用n次分部积分法,上下再同乘n!,可得:

( n 2 ) ! ( 2 n + 1 ) ! \frac{(n^2)!}{(2n+1)!} (2n+1)!(n2)!

所以只需要预处理一下分子和分母的阶乘,对于分母采取逆元(逆元讲解链接逆元
然后直接输出就完事了

代码

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
const int N=2e6 +9;
const int mod=998244353;
// #define TDS_ACM_LOCAL
ll fz[N], fm[N];
int n;

ll quick_pow(ll a, ll b)
{ 
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

void init(){
    fz[1]=1;
    for(int i=2; i<=N; i++) fz[i]=(fz[i-1]*i)%mod;
    fm[N]=quick_pow(fz[N], mod-2);
    for(int i=N-1; i>=0; i--)   fm[i]=fm[i+1]*(i+1)%mod;
}

void solve(){
    while(cin>>n){
        ll ans=(fz[n]*fz[n])%mod *fm[2*n+1]%mod;
        cout<<ans<<endl;
    }
    return ;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
    freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
    freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
    init();
    solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值