F、Infinite String Comparision

给出两个字符串a,b,询问的是在无限自循环连接的前提下两个字符串的大小关系

比赛时应付写法,无限循环不可能去真正在无限的时间才可能出答案,那么在一定时间的循环节之内就可以得到答案,也就是说如果你没有很好的办法去证明出正确的解法,那么我们根据题目给出的时间范围和数据输入,在一定的常数内通过游标的方式一直比较两个字符串,如果在一定次数内没有得到谁大谁小那么就直接跳出循环判断相等。否则就判断大小关系,常数可以自己把握。

#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline void write(__int128 x) { if (!x) { putchar('0'); return; } char F[50]; __int128 tmp = x > 0 ? x : -x; if (x < 0)putchar('-');  int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';     tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]); }
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 55;
#define stop system("pause")
#define PI acos(-1.0)
inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
int main(){
    js;
    string a,b;
    bool flag = false;
    while(cin>>a>>b){
        flag = false;
        int i = 0 , j = 0;
        int num = 1000*max(a.size(),b.size());
        while(num--){
            if(a[i] > b[j]){
                puts(">");flag = true;break;
            }
            else if(a[i] < b[j]){
                puts("<");flag = true;break;
            }
            else{
                i++;j++;
                if(i == a.size()) i = 0;
                if(j == b.size()) j = 0;
            }
        }
       if(!flag) puts("=");
    }
}

方法2、来自mutou01的题解,通过一定的证明,运用string类的连接和判断输出答案。

#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define all(__vv__) (__vv__).begin(), (__vv__).end()
#define endl "\n"
#define pai pair<int, int>
#define mk(__x__,__y__) make_pair(__x__,__y__)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const int MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar())    s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; }
inline void print(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-');    int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';        tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]); }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;    while (b) { if (b & 1)    ans *= a;        b >>= 1;        a *= a; }    return ans; }    ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline int lowbit(int x) { return x & (-x); }

const int N = 1e5 + 7;

int main() {
    js;
    string a, b;
    while (cin >> a >> b) {
        if (a + b == b + a)    cout << '=' << endl;
        else if (a + b < b + a)    cout << '<' << endl;
        else cout << '>' << endl;
    }
    return 0;
}

J、Easy Integration

图片说明 给出n的情况下的答案

图片说明

// 对这个题目都写出公式来了,逆元和阶乘在MOD下的答案就不用多说了把

#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline void write(__int128 x) { if (!x) { putchar('0'); return; } char F[50]; __int128 tmp = x > 0 ? x : -x; if (x < 0)putchar('-');  int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';     tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]); }
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 998244353;
const int maxn = 55;
#define stop system("pause")
#define PI acos(-1.0)
inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
ll qpow(ll x,ll y){
     x %= mod;
    ll ans = 1;
    while(y){
        if(y&1) ans = ans*x%mod;
        x = x*x%mod;
        y >>= 1;
    }
    return ans;
}
ll fac[2000005];
int main(){
    fac[0] = 1;
    for(int i = 1 ; i < 2000005;  ++i) fac[i] = fac[i-1]*i%mod;
    int n;
    js;
    while(cin>>n){
        cout<<qpow(fac[n],2ll)*qpow(fac[2*n+1],998244351ll)%mod<<endl;
    }
}