codeforces hello 2020

Topic links: https://codeforces.com/contest/1284

A:New Year and Gaming

Subject to the effect that there are n string S . 1 , S 2 .... S n and m string t . 1 , t 2 .... t n , for each year, and needs to find the corresponding S corresponding to t and connecting them. Rules starting from the first year, corresponding to the first string, moving every year after a string backwards when it reaches the last string, the next year will return to the first string.
N input samples to the effect string S . 1 , S 2 .... S n , m after the input string T . 1 , T 2 .... T n . You then need to answer the q inquiry, asking each for the year y represents an integer. Each numerical value in the range of n, m (1≤n, m≤20) , less than the string length is greater than 1 10,1≤q≤2020,1≤y≤10 . 9 .

My solution to this question is to find the corresponding position of the two strings are sequences, can be directly%, if it is 0 or turn into the final n to m.

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
string ss1[25],ss2[25];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        cin>>ss1[i];
    for(int i=1;i<=m;i++)
        cin>>ss2[i];
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int t;
        scanf("%d",&t);
        int t1=t%n;
        int t2=t%m;
        if(!t1)t1=n;
        if(!t2)t2=m;
        cout<<ss1[t1]<<ss2[t2]<<endl;
    }
    return 0;
}

B:New Year and Ascent Sequence

Subject to the effect in the combination of any two sequences of n given (without changing the order, in combination with their) presence in ascending order (i.e. the number smaller than the number of positions on the front position) after.
Input integer n (1≤n≤1e5), the next row n (1 ≦ L represents the length of this sequence, l) at the beginning, followed by a digit S to a l l I, J (0 ≦ S I, J ≦ 10 . 6 ), and all l not exceed 1e5.

This problem solution of stored maximum and minimum values ​​of each sequence, and determines whether there is ascending this sequence itself. After the minimum number +1 prefix do and, if there is ascending in itself, a minimum value of +1 to 0 and added the prefix. Finally, the maximum value can be taken from the prefix and.

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
const int maxn=1e6+7;
int minn[maxn],maxx[maxn];
bool ok[maxn];
int mmm[maxn];
int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int l;
        scanf("%d",&l);
        int a;
        int max1,min1;
        scanf("%d",&max1);
        min1=max1;
        for(int j=2;j<=l;j++)
        {
            scanf("%d",&a);
            if(a<min1)min1=a;
            if(a>min1)ok[i]=1;
            if(a>max1)max1=a;
        }
        maxx[i]=max1;
        minn[i]=min1;
        if(ok[i])mmm[0]++;
        else mmm[min1+1]++;
    }
    for(int i=1;i<maxn;i++)
        mmm[i]+=mmm[i-1];
    for(int i=1;i<=n;i++)
    {
        if(ok[i])sum+=n;
        else{
            sum+=mmm[maxx[i]];
        }
    }
    cout<<sum<<endl;
    return 0;
}

C:New Year and Permutation

This problem is to find a continuous sequence, so that maximum minus minimum length equal to minus one, it can be seen are in line with the size of contiguous subsequence. Whereby the arrangement need only count on the line.

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
const int maxn=250007;
ll fa[maxn];
int main()
{
    int n,mod;
    fa[0]=1;
    scanf("%d%d",&n,&mod);
    for(int i=1;i<=n;i++)fa[i]=fa[i-1]*i%mod;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=((n-i+1)*(fa[i]*fa[n-i+1]%mod))%mod;
        sum%=mod;
    }
    cout<<sum<<endl;
}

D did not write it, and so finished the fix.

Guess you like

Origin www.cnblogs.com/gxywjl/p/12152217.html