Codeforces Global Round 10

This kind of big market is full of gods fighting, and it’s too difficult to
lose points to me for this kind of food. The gods fight, and the people suffer.

A - Omkar and Password

The analysis shows that as long as the array elements are not all equal, the answer is 1, and if the array elements are all equal, the answer is n.

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[N];
int n;
int main()
{
    
    
    IO;
    int T;
    cin>>T;
    while(T--)
    {
    
    
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        bool ok=1;
        for(int i=2;i<=n;i++) 
            if(a[i]!=a[1])
            {
    
    
                ok=0;
                break;
            }
        if(ok) cout<<n<<endl;
        else cout<<1<<endl;
    }
    return 0;
}

B - Omkar and Infinity Clock

For math problems, you can find the pattern with a little writing.

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200010;
ll a[N];
ll n,k;
int main()
{
    
    
    IO;
    int T;
    cin>>T;
    while(T--)
    {
    
    
        cin>>n>>k;
        ll maxa=-2e9,mina=2e9;
        for(int i=1;i<=n;i++) 
        {
    
    
            cin>>a[i];
            maxa=max(maxa,a[i]);
            mina=min(mina,a[i]);
        }
        if(k&1)
        {
    
    
            for(int i=1;i<=n;i++) cout<<maxa-a[i]<<" ";
            cout<<endl;
        }
        else
        {
    
    
            for(int i=1;i<=n;i++) cout<<a[i]-mina<<" ";
            cout<<endl;
        }
        
    }
    return 0;
}

C - Omkar and Waterslide

Greedy Luogu's original question The
title conversion is equivalent to adding a hole.
If a[i-1]>a[i]the need filled out a[i-1]-a[i]and then converted to add the first i-1pit that is, f[i-1]
if a[i-1]<=a[i]the results suggested that i-1while one can live the way to fill in the pit of the ipit

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200010;
ll a[N];
ll n;
ll f[N];
int main()
{
    
    
    IO;
    int T;
    cin>>T;
    while(T--)
    {
    
    
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=n;i++) f[i]=f[i-1]+max(a[i-1]-a[i],0ll);
        cout<<f[n]<<endl;
    }
    return 0;
}

Just did three questions

D - Omkar and Bed Wars

Refer to the answer of Positive Solutions %%% Orz
First consider the case illegal:
s[i-1]=Land s[i+1]=Lit s[i]=Lis the person to your right hits you on the left who did not hit you but you hit your left people.
s[i-1]=Rand s[i+1]=Rit s[i]=Ris to your left who hits you on the right person did not hit you but you have beaten your right.
I found that in these two cases of non-compliance, there cannot be 3 consecutive identical characters (Orz, I messed up a p at the time, this analysis is wonderful),
so count the number of consecutive identical characters cnt, and then it becomes impossible to have 3 Same characters consecutively. If the number of consecutive characters is the same, cntthen it will cnt/3cost.
Note that if it is a ring, first find a point and spend 1 cost to break the ring, and the final cost is(cnt-1)/3+1

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200010;
ll a[N];
int n;
int main()
{
    
    
    IO;
    int T;
    cin>>T;
    while(T--)
    {
    
    
        int n;
        cin>>n;
        string s;
        cin>>s;
        int cnt=0;
        while(s.size()&&s[0]==s.back())
        {
    
    
            cnt++;
            s.pop_back();
        }
        if(s.empty())
        {
    
    
            if(cnt<=2) cout<<0<<endl;
            else if(cnt==3) cout<<1<<endl;
            else cout<<(cnt-1)/3+1<<endl;
        }
        else
        {
    
    
            int res=0;
            s.push_back('$');
            for(int i=0;i<s.size()-1;i++)
            {
    
    
                cnt++;
                if(s[i]!=s[i+1])
                {
    
    
                    res+=cnt/3;
                    cnt=0;
                }
            }
            cout<<res<<endl;
        }
    }
    return 0;
}

It seems that dp can also do this question, but I can’t. Look back and see what other big guys have written and make up for it.
Come on~

Guess you like

Origin blog.csdn.net/Fighting_Peter/article/details/108053634