Educational Codeforces Round 164 (Rated for Div. 2)

A. Painting the Ribbon

显然,Alice 的理想操作是每种颜色均匀分布

而 Bob 的理想操作是选择当前数量最多的颜色,将其他的都喷为这个颜色

所以只要判断 k 是否大于 $n-mx$ 即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=1e9+7;

int n,m,k;

void solve(){
    cin>>n>>m>>k;
    if(m==1||k>=n-1){
        cout<<"No\n";
        return;
    }    
    int ned=n-ceil(1.0*n/m);
    if(k<ned)cout<<"Yes\n";
    else cout<<"No\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

B. Make It Ugly

注意到,操作只会使中间的元素进行变化,即 $a_1,a_n$ 会保持不变

那么目标就是找到两个不同的数,删去他们之前的相同数的片段

找到最短的相同片段,即为答案

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=3e5+7, mod=1e9+7, inf=1e9;

int n,a[N];

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int ans=inf,tmp=0;
    for(int i=1;i<=n;i++){
        if(a[i]==a[1])tmp++;
        else if(tmp)ans=min(ans,tmp),tmp=0;
    }
    if(tmp!=n)ans=min(ans,tmp);
    if(ans==inf)cout<<"-1\n";
    else cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

C. Long Multiplication

其实就是使 x,y 最接近的,即对每一位判断,把大的给当前小的,小的给当前大的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=1e9+7;

string s,t;

bool cmp(string s,string t){
    if(s.size()>t.size())return 1;
    if(t.size()>s.size())return 0;
    for(int i=0;i<s.size();i++){
        if(s[i]-'0'>t[i]-'0')return 1;
        if(s[i]-'0'<t[i]-'0')return 0;
    }
    return 1;
}

void solve(){
    cin>>s>>t;
    string as,at;
    as=at="";
    for(int i=0;i<s.size();i++){
        int l=s[i]-'0',r=t[i]-'0';
        if(l>r)swap(l,r);
        if(cmp(as,at))swap(as,at);
        as+=(r+'0'),at+=(l+'0');
    }
    cout<<as<<endl;
    cout<<at<<endl;
}  

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

D. Colored Balls

假设当前球的总量为 $x$,当前数量最多的球的数量为 $a_i$,如果 $a_i * 2 > x$,那么当前的值即为 $a_i$,反之,当前的值为 $x/2$。

题上给出所有球数总和不超过 5000,即可以对所有球的数量的情况计算当前数量为最多数量时,各种球总量对应的方案数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=998244353;

int n,a[N];
ll f[N],ans;

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    f[0]=1;
    for(int i=1;i<=n;i++){
        int x=a[i];
        for(int j=5000;j>x;j--){
            ans=(((j+x)/2+(j+x)%2)*f[j]%mod+ans)%mod;
            if(j+x<=5000)f[j+x]=(f[j+x]+f[j])%mod;
        }
        for(int j=x;j>=0;j--){
            ans=(ans+f[j]*x%mod)%mod;
            if(j+x<=5000)f[j+x]=(f[j+x]+f[j])%mod;
        }
    }
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)solve();
    return 0;
}
Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 11, 2025 16:27 +0800
发表了95篇文章 · 总计15万2千字
永远相信美好的事情即将发生。
使用 Hugo 构建
主题 StackJimmy 设计