codeforce Hello 2020

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

 

A.New Year and Naming

The digital, find the corresponding string array named s + t corresponding string array name, can take the remainder

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    string s[30],t[30];
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<m;i++)cin>>t[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y;
        cin>>y;
        cout<<s[(y-1)%n]<<t[(y-1)%m]<<endl;
    }
    return 0;
} 

 

B.New Year and Ascent Sequence

N to the number of groups, the number of how many the number of each first described, and then gives the order, the number of groups n may be engaged around, forms an integral number of groups n * n

If the array a [] in the presence of i <j and a [i] <a [j], is to meet the requirements, it is calculated how much the number of groups n * n groups in total compliance.

Ideas: a set of numbers and their own splicing can also be someone to fight in the front / rear.

If it itself contains ascending order, regardless of how the fight will meet the requirements, put a bunch of this type of number, the contribution of each group to answer should be n * 2-1, because before and after the group phase with himself, regardless.

However, this contribution to the repeated calculation, it should be changed to (n-cnt) * 2-1, cnt off when the i-th, the number of sets itself contains ascending.

Repeat calculate the contribution of the sample

input:
3
2 0 2
2 0 2
2 0 2
output:
9

If the ASC itself does not contain (i.e., full descending), the maximum value of the recording array H [i], the minimum value of L [i], the number of which discharge another pile.

In this pile, each contribution to the number of answers, the stack H [i] is greater than the number of L [the group i] is.

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int s[1000050];
int flag[maxn],h[maxn],l[maxn];
vector<int> high,low;
int main()
{
    long  long years = 0 ;
    int n, cnt = 0 ;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int len;
        cin>>len;
        int tmph=0,tmpl=1e6;
        for(int j=0;j<len;j++)
        {
            scanf("%d",&s[j]);
            if(j!=0&&s[j]>s[j-1])flag[i]=1;
            tmph=max(tmph,s[j]);
            tmpl=min(tmpl,s[j]);
        }
        if(!flag[i])
        {
            h[i]=tmph;
            l[i]=tmpl;
            high.push_back(tmph);
            low.push_back(tmpl);
        }
    } 
    sort(high.begin(),high.end());
    sort(low.begin(),low.end());
    int size=high.size();
    for(int i=0;i<n;i++)
    {
        if(flag[i]==1)ans+=((n-cnt)*2-1),cnt++;
        else
        {
            int num=upper_bound(high.begin(),high.end(),l[i])-high.begin();
            ans+=size-num;
        }
    }
    cout<<ans<<endl;
    return 0;
} 

 

C.New Year and Permutation

Full array of n (n! Case) where to find, in each case i find all the following conditions, the number of group j, the answer is the number of groups and in all cases

From a [i] to a [j], the maximum value of the minimum value min = ji max-

Violence enumeration answer: 1,6,32,180,1116,7728,59904,518400

Enumeration From 3 to 4 found pushed rule logically should be added to n = r 3, but the coefficient was found to direct regular * (n + 1) / 2 of

#include<bits/stdc++.h>
using namespace std;
int jie[250050];
int extgcd(int a,int b,int& x,int& y)
{
    int d=a;
    if(b!=0)
    {
        d=extgcd(b,a%b,y,x);
        and - = (a / b) * x;
    }
    else 
    {
        x=1;
        and = 0 ;
    }
    return d;
}
int mod_inverse(int a,int m)
{
    int x,y;
    extgcd(a,m,x,y);
    return(m+x%m)%m;
}
int main()
{
    int n,m;
    long long r=0;
    cin>>n>>m;
    jie[1]=1;
    for(int i=2;i<=n;i++)
    {
        jie[i]=1ll*jie[i-1]*i%m;
    }
    for(int i=1;i<=n;i++)
    {
        r=(r+1ll*jie[i]*jie[n-i+1]%m)%m;
    }
    
    //*1,*1.5,*2,*2.5,*3,*3.5......
    //2*1=1,4*1.5=6,16*2=32,72*2.5=180
    r=r*(n+1)%m;
    r=r*mod_inverse(2,m)%m;//除以2等于乘上逆元 
    cout<<r<<endl;
    return 0;
} 

 

D. New Year and Conference

考完试再补:)

Guess you like

Origin www.cnblogs.com/myrtle/p/12150790.html