首页 > 其他分享 >Educational Codeforces Round 107 (Rated for Div. 2)

Educational Codeforces Round 107 (Rated for Div. 2)

时间:2023-08-16 16:25:50浏览次数:44  
标签:Educational Rated const int double typedef long Codeforces define

Educational Codeforces Round 107 (Rated for Div. 2)

A - Review Site
思路:数1和3的个数
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=250+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void init(){

}
void solve(){
    int n;cin>>n;
    int ans=0;
    for(int i=0,x;i<n;++i){
        cin>>x;
        if(x==1||x==3)ans++;
    }cout<<ans<<'\n';
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    init();
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

B - GCD Length

思路1:令gcd(x,y)=pow(10,c-1),x和y分别一直乘3和7,直到达到a和b位数

思路2:x=pow(10,a-1)+pow(10,c-1),y=pow(10,b-1)

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=250+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void init(){

}
void solve(){
    int a,b,c;cin>>a>>b>>c;
    int x,y,z;
    z=pow(10,c-1);
    x=y=z;
    while(x<pow(10,a-1))x*=3;
    while(y<pow(10,b-1))y*=7;
    cout<<x<<' '<<y<<'\n';
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    init();
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

C - Yet Another Card Deck

思路:由于数的范围很小,维护每个数的最小位置即可,更新时枚举每个数,若位置在其前面则后移

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=250+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void init(){

}
void solve(){
    int n,q;cin>>n>>q;
    vector<int>c(55,n+5);
    for(int i=1,x;i<=n;++i){
        cin>>x;
        c[x]=min(c[x],i);
    }
    for(int i=0,x;i<q;++i){
        cin>>x;
        cout<<c[x]<<' ';
        for(int j=1;j<=50;++j){
            if(c[j]<c[x])c[j]++;
        }
        c[x]=1;
    }
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //cin>>t;
    init();
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

D - Min Cost String

思路:可以看出规律 a ab ac ad... b bc bd... 

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=250+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void init(){

}
void solve(){
    int n,k;cin>>n>>k;
    vector<int>f(30,0);
    string s;

    for(int i=0;i<k;++i){
        s.push_back('a'+i);
        for(int j=i+1;j<k;++j){
            s.push_back('a'+i);
            s.push_back('a'+j);
        }
    }
    string ans;
    while(ans.size()<n){
        ans+=s;
    }
    for(int i=0;i<n;++i)cout<<ans[i];
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //cin>>t;
    init();
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

E - Colorings and Dominoes

思路:将求每个方案的数量和的问题,转化为求每个多骨牌的贡献;由于染蓝色和染红色的多骨牌不同,可以分别求两种牌的贡献;

对于一行\一列中连续的k个'o'的多骨牌摆放方案数其实一样,那么预处理出f[i],表示连续i个'o'的所有摆放方案能放的多骨牌数;

对于每个连续的'o'串,贡献为f[i]*2all-i

f[i]的状态转移:

当第i个为蓝色,没有贡献,f[i]+=f[i-1]

当第i个为红色:第i-1个为蓝色时,第i个和第i-1个无法放多骨牌,f[i]+=f[i-2]

        第i-1个为红色时,给前i-2个都新增一个方案,f[i]+=f[i-2];第i个和第i-1个放一个多骨牌,前i-2个有2i-2个方案数,f[i]+=2i-2

即f[i]=f[i-1]+2f[i-2]+2i-2

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=3e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void init(){

}
void solve(){
    int n,m;cin>>n>>m;
    vector<vector<char>>g(n+1,vector<char>(m+1));
    int all=0;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)cin>>g[i][j],all+=(g[i][j]=='o');
    int ans=0;
    vector<int>fact(N),f(N);
    fact[0]=1;
    for(int i=1;i<=all;++i)fact[i]=fact[i-1]*2%mod;
    f[0]=f[1]=0;
    for(int i=2;i<=max(n,m);++i)f[i]=((f[i-1]+2*f[i-2])%mod+fact[i-2])%mod;
    for(int i=1;i<=n;++i)
        for(int j=1,k;j<=m;++j){
            k=j;
            while(j<=m&&g[i][j]=='o')j++;
            ans=(ans+f[j-k]*fact[all-j+k]%mod)%mod;
        }
    for(int j=1;j<=m;++j)
        for(int i=1;i<=n;++i){
            int k=i;
            while(i<=n&&g[i][j]=='o')i++;
            ans=(ans+f[i-k]*fact[all-i+k]%mod)%mod;
        }
    cout<<ans;
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //cin>>t;
    init();
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

标签:Educational,Rated,const,int,double,typedef,long,Codeforces,define
From: https://www.cnblogs.com/bible-/p/17635392.html

相关文章

  • Codeforces Round 765 (Div. 2) A-E
    A.AncientCivilization好像就是对每个二进制位看一下0多还是1多,选择多的那个数就好了。vp的时候直接猜的,交了一发直接过了voidsolve(){intn=read(),m=read();vector<int>cnt0(m+1),cnt1(m+1);for(inti=1;i<=n;i++){intx=read();for(int......
  • Codeforces Round 893(div2)
    CodeforcesRound893(div2)[A题传送门](Problem-A-Codeforces)A题意:我们有a+b+c个瓶盖,选手1可以拿指定的a个或者c个里面的一个,选手2可以拿指定的b个或者c个里面的一个,可以拿完最后一个的即为获胜者,每个人都有最优策略。A思路:这个题一开始想错了,主要是没有读懂题意,理解清楚......
  • Codeforces Round 892 (Div. 2)
    CodeforcesRound892(Div.2)A.UnitedWeStand简述题意给定一个长度为$n$的数列$a$,要求将$a$的每个元素分配到数列$b$,$c$中,满足以下两个要求$b,c$不为空,即$l_b\geq1,l_c\geq1$。对于任意$i$和$j$$(1\leqi\leql_b,1\leq......
  • Codeforces Global Round 15
    CodeforcesGlobalRound15A-SubsequencePermutation思路:找出原串与排序后的串不同的个数#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn;cin>>n;strings;cin>>s;stringt=s;sort(t.begin(),t.end());intans=0;......
  • Codeforces Round 892 (Div. 2) A-E
    A.UnitedWeStand题意:给出一个长为\(n\)的数组\(a\),将其中的元素分别放到空数组\(b\)和\(c\)中,使得\(c\)中的任意一个元素都不是\(b\)中任意一个元素的因数,并且两个数组都不是空数组Solution把\(a\)中最小的数放到\(b\),其它的都放到\(c\),一定可以保证要求成立voidsolve(){......
  • Codeforces Ronud 892(Div.2)
    CodeforcesRonud892(Div.2)关于A题我有话说传送门题意给定一个长度为n的数组a,问能否将元素全部放入两个空数组b和c中,使得b和c数组同时满足非空,且c数组中没有任何数是b数组中的数的除数,如果可以输出一种存储方案,不可以就输出-1思路当天晚上一开始没有做出来,我一开始的思路是......
  • CodeForces-1798#B 题解
    正文开个数组\(last_k\)统计\(a_{i,j}\)最后买彩票的时间,再开一排桶\(day_t\)记录该天最后买彩票的有哪些人(即:有\(p\)满足\(last_p=t\)的集合)。将\(last_k\)放入\(day_t\)中,判断\(day_t\)中是否存在空桶,若有则无解(因为没有人在当天是最后买彩票的)。因为本题是......
  • 2023.08.12 codeforces round 892 div2
    年轻人的第三场div2(已完成:ABCDE)rank:1265solved:4ratingchange:+276newrating:1323A.UnitedWeStand题意:给定一个数列a,问是否能分成两个非空的数列b和c,使得c中任意一个数不是b中任意一个数的因子;若x是y的因子则有x<=y;因此不妨将数列的最大值放入c,把剩下的数放入b;注意数列中......
  • 某谷 Rated 比赛泛做
    P9535「YsOI2023」连通图计数非常好题目,爱来自湖南。\(m=n-1\)等价于给定度数求树的个数,这是一个经典题,在「HNOI2004」树的计数有描述,即利用Prufer序列得到答案为\(\binom{n-2}{(d_1-1)(d_2-1)\ldots(d_n-1)}\)。\(m=n\)即基环树,对于整个大环建立一个虚点,该点向环上的所......
  • Codeforces Round 892 (Div. 2)
    Preface最接近橙名的一场,可惜给我一个小时也没想到E的关键点,后面徐神一点拨就懂了虽然现在这个号已经到渡劫局了但因为之前有场比赛给了ztc一份代码然后他直接没咋改交上去了,估计下次rollRating的时候这个号要掉200来分了嘛不过也无所谓反正下次打另一个号冲分,而且像我这种永......