Educational Codeforces Round 79 (Rated for Div. 2)

Exam link

https://codeforces.com/contest/1279

A. New Year Garland

Red, green, and blue light, the same color can not be adjacent, asked if he could link the
selected color that lights up a, then there must be a minimum of a-1 other lights, the lights spaced

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 200100;
const int M = 1e9+7;
int n,m,k,t;
int a[4];
 
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
#endif
    cin(t);
    while(t--)
    {
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if(a[0]+a[1] >= a[2]-1)
        {
            puts("YES");
        }
        else puts("NO");
    }
    return 0;
}

B. Verse For Santa

In order to recite poetry, a total of s seconds, you can skip once recite, recite asked to skip what time can recite more of the total
simulation look like, and when the time is greater than s, minus the previous longest memorize, is less than s, that can be more general recitation

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 100100;
const int M = 1e9+7;
int n,s,t;
 
int a[maxn];
 
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
#endif
    cin(t);
    while(t--)
    {
        cin(n);cin(s);
        for(int i = 0; i < n; i++) 
        {
            cin(a[i]);
        }
        ll sum = 0;
        ll idx = 0;
        ll mx = 0;
        for(int i = 0; i < n; i++) 
        {
            sum += a[i];
            if(a[i] > mx)
            {
                mx = a[i];
                idx = i;
            }
            if(sum > s)
            {
                if(sum-mx > s) idx = -1;
                else break;
            }
        }
        if(sum <= s) idx = -1;
        printf("%d\n",idx+1);
    }
    return 0;
}

C. Stack of Presents

simulation

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 100100;
const int M = 1e9+7;
int n,m,t;
 
int a[maxn];
int b[maxn];
bool vis[maxn];
 
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
#endif
    cin>>t;
    while(t--)
    {   
        mem(vis,0);
        cin>>n>>m;
        for(int i = 0; i < n; i++) 
        {
            cin>>a[i];
        }
        for(int i = 0; i < m; i++) 
        {
            cin>>b[i];
        }
        ll ans = 0;
        int j = 0, i = 0;
        
        for(; i < m; i++) 
        {   
            //cout<<ans<<' ';
            if(vis[b[i]]) ans++;
            else
            {
                for(; j < n; j++)
                {   
                    vis[a[j]] = 1;
                    if(a[j] == b[i])
                    {   
                        ans += ((j-i)*2+1);
                        break;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

D. Santa's Bot

That is, before the election of a person x, then this person's ki inside elect a y, and then randomly assigned to one person z, if z need this y, then, is the correct operation, find the probability of correct operation of
honest, English TMD is too important I get a case for it
first select the person 1, No. 2 if you choose a gift, can only be assigned to 2, the probability \ (1/2 * 1/2 * 1/2 = 1/8 \)
If you select No. 1 gift, can be assigned to 1, the probability \ (1/2 * 1/2 * 1/4 = 1 \)
and then select the person 2, No. 1 can only choose a gift, can be assigned to 1, the probability \ (* 1 * 1 1/2 = 1/2 \)
so the overall probability \ (7/8 \)

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 1001000;
const int M = 998244353;

ll ksm(ll a,ll b)
{
    ll res = 1;
    while (b)
    {
        if(b&1) res = (res*a)%M;
        a = (a*a)%M;
        b /= 2;
    }
    return res%M;
}


vector<int> a[maxn];
int b[maxn];

int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
#endif
    ll n,k;
    cin>>n;
    int sum = 0;
    for(int i = 0; i < n; i++) 
    {
        cin>>k;
        for(int j = 0,x; j < k; j++) 
        {
            cin>>x;
            sum++;
            a[i].push_back(x);
            b[x]++;
        }
    }
    ll nn = ksm(n,M-2);
    ll ans = 0;
    for(int i = 0; i < n; i++) 
    {
        ll res = 0;
        ll x = a[i].size();
        x = ksm(x,M-2);
        for(auto j : a[i])
        {
            res = (res + ((x*b[j])%M*nn)%M)%M;
        }
        ans = (ans+res)%M;
    }
    ans = (ans*nn)%M;
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/hezongdnf/p/12110227.html