F 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
题目传送门
思路
由:
∫ 0 1 ( x − x 2 ) n d x ∫^1_0 (x−x^2)^ndx ∫01(x−x2)ndx
可推出:
∫ 0 1 x n ( 1 − x ) n d x ∫^1_0 x^n(1−x)^ndx ∫01xn(1−x)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;
}