Educational Codeforces Round 123 (Rated for Div. 2)

Educational Codeforces Round 123 (Rated for Div. 2)

A - Doors and Keys

#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e5+5;

void solve()
{
    string s;
    cin>>s;
    int a=0,b=0,c=0,fg=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='r') a++;
        if(s[i]=='g') b++;
        if(s[i]=='b') c++;
        if(s[i]=='R' && !a || s[i]=='G' && !b || s[i]=='B' && !c) 
        {
            fg=1; break;
        }
    }
    if(!fg) cout<<"YES\n";
    else cout<<"NO\n";
}
signed main()
{
    int T=1;
    cin>>T;
    while(T--) solve();
}

B - Anti-Fibonacci Permutation

  • 小构造
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e5+5;

void solve()
{
    int n;
    cin>>n;
    if(n==3)
    {
        cout<<"3 2 1\n";
        cout<<"1 3 2\n";
        cout<<"3 1 2\n";
    }
    else 
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=n-i+1;j>=1;j--) cout<<j<<' ';
            for(int j=n;j>n-i+1;j--) cout<<j<<' ';
            cout<<"\n";
        }
    }
}
signed main()
{
    int T=1;
    cin>>T;
    while(T--) solve();
}

C - Increase Subarray Sums

分析:

  • 前缀和,暴力枚举
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e5+5;
int a[N],s[N],tp[N];
void solve()
{
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;i++) 
    {
        cin>>a[i];
        s[i]=s[i-1]+a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        tp[i]=-1e9;
        for(int j=1;j+i-1<=n;j++)
        {
            tp[i]=max(tp[i],s[j+i-1]-s[j-1]);
        }
        ans=max(ans,tp[i]);
    }
    cout<<ans<<' ';
    for(int i=1;i<=n;i++)
    {
        ans=0;
        for(int j=1;j<=n;j++)
        {
            ans=max(ans,tp[j]+x*min(j,i));
        }
        cout<<ans<<' ';
    }
    cout<<endl;
}
signed main()
{
    int T=1;
    cin>>T;
    while(T--) solve();
}

D - Cross Coloring

分析:

  • 思维+结论
  • 从前往后覆盖,所以要从后往前标记,最后看有多少不同的块
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e6+5, mo=998244353;
int x[N],y[N];
set <int> sx,sy;
int ksm(int a,int b,int p=mo)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%p;
        a=a*a%p; b>>=1;
    }
    return ans;
}
void solve()
{
    int n,m,k,q;
    cin>>n>>m>>k>>q; 
    for(int i=1;i<=q;i++) scanf("%lld%lld",&x[i],&y[i]);
    int ans=0;
    sx.clear(); sy.clear();
    for(int i=q;i>=1;i--)
    {
        if(!sx.count(x[i]) || !sy.count(y[i]))
        {
            sx.insert(x[i]); sy.insert(y[i]);
            ans++; // 每次最多贡献一块不同的
        }
        if(sx.size()==n || sy.size()==m) break;
    } 
    ans=ksm(k,ans);
    cout<<ans<<"\n";
}
signed main()
{
    int T=1;
    cin>>T;
    while(T--) solve();
}

E - Expand the Path

分析:

  • 覆盖小结论+模拟+容斥

  • 首先能移动到的方格肯定是连续的一片,因此我们只需要考虑这一片的边界即可,边界分为右上和左下:

    • 右上:第一次向右走的时候,就把能向右走的格子数走完,最后一次向下也走到底,最后到 ( n , n ) (n,n) (n,n)
    • 左下:第一次向下走的时候,就把向下走的走完,最后一次向右走走到底,最后到 ( n , n ) (n,n) (n,n)
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N=1e5+5;
void solve()
{
    int n;
    cin>>n;
    string s; 
    cin>>s;
    int x=1,y=1;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R') y++;
        else x++; 
    }
    if(x==1 || y==1) cout<<n<<"\n"; // 特判
    else 
    {
        int dx=n-x, dy=n-y, ans=0;
        y=1; x=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='D') x++;
            else 
            {
                ans+=x*(n-y);
                y+=dy; dy=0;
                y++; x=0;
            }
        }
        if(x) ans+=x*(n-y);
        x=1; y=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='R') y++;
            else 
            {
                ans+=y*(n-x);
                x+=dx; dx=0;
                x++; y=0;
            }
        }
        if(y) ans+=y*(n-x);
        cout<<n*n-ans<<"\n";
    }
}
signed main()
{
    int T=1;
    cin>>T;
    while(T--) solve();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yezzz.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值