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

ps:原题可以点击题目查看

F:Infinite String Comparision

题意:给定两个字符串,字符串可以以本身为循环节无限延长。问可以无限延长的两个字符串的大小关系。

思路:两个长度分别为la,lb的字符串a,b,需要比较的最短长度为la+lb-gcd(la,lb),然后逐位比较大小即可。

AC代码:

#include
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define INF 0x3f3f3f
#define fi first
#define se second
#define it iterator
#define ins insert
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define pq priority_queue
#define ll long long
#define ull unsigned long long
#define mem(a,x) memset(a,x,sizeof(a))
#define cio ios::sync_with_stdio(false)  // 不能和C的输入混用

inline ll lgcd(ll a,ll b){return b == 0? a:lgcd(b, a % b);}
inline int lowbit(int x){return x&(-x);}

#define S(n) setiosflags(ios::fixed)  << setprecision(n)
#define T int t;scanf("%d",&t);while(t--)
#define Ce cout << endl
#define C(n,m) cout << S(n) << m << endl
#define CY cout << "YES" << endl
#define CN cout << "NO" << endl
#define Cy cout << "Yes" << endl
#define Cn cout << "No" << endl

 
int main()
{
    string a, b;
    while(cin>>a>>b){      
        int la = a.size();
        int lb = b.size();
        int l = la+lb-gcd(la,lb);
        int flag = 0;
        for(int i = 0; i < l; i++){
            int k1 = i%la;
            int k2 = i%lb;
            if(a[k1]<b[k2]){
                flag = -1;
                break;
            }else if(a[k1]>b[k2]){
                flag = 1;
                break;
            }
        }
        if(flag==-1){
            cout << "<" << endl;
        }else if(flag==0){
            cout << "=" << endl;
        }else if(flag==1){
            cout << ">" << endl;
        }
    }
    return 0;
}

J:Easy Integration

题意:没啥好讲的,就是一个数学题,求积分。

思路:数学菜鸡留下泪水,只知道最后得出公式是 (n!)^2/(2*n+1)!,预处理一下各数阶乘取余,最后分数取模取余即可。

AC代码:

#include
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define INF 0x3f3f3f
#define fi first
#define se second
#define it iterator
#define ins insert
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define pq priority_queue
#define ll long long
#define ull unsigned long long
#define mem(a,x) memset(a,x,sizeof(a))
#define cio ios::sync_with_stdio(false)  // 不能和C的输入混用

inline ll lgcd(ll a,ll b){return b == 0? a:lgcd(b, a % b);}
inline int lowbit(int x){return x&(-x);}

#define S(n) setiosflags(ios::fixed)  << setprecision(n)
#define T int t;scanf("%d",&t);while(t--)
#define Ce cout << endl
#define C(n,m) cout << S(n) << m << endl
#define CY cout << "YES" << endl
#define CN cout << "NO" << endl
#define Cy cout << "Yes" << endl
#define Cn cout << "No" << endl


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

ll s[2000050];

void init()
{
	s[1] = 1;
	for(int i = 2; i <= 2000010; i++){
		s[i] = s[i-1]*i%mod;
	}
}

int main()
{
	init();
    ll n;
    while(cin>>n){
    	ll a = s[n]*s[n]%mod;
    	ll b = s[2*n+1];
    	ll c = inv(a,b);
        cout << c << endl;
    }
    return 0;
}

你可能感兴趣的:(题解)