Educational Codeforces Round 107 (Rated for Div. 2) 题解

A - Review Site

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
const int N = 1e5 + 10;
using namespace std;



int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int tot=0;
        for(int i=1;i<=n;i++){
            int k;
            cin>>k;
            if(k==1) tot++;
            else if(k==3) tot++;
        }
        cout<<tot<<endl;
    }
    return 0;
}

B - GCD Length

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
const int N = 1e5 + 10;
using namespace std;



int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll x,y,z;
        cin>>x>>y>>z;
        ll num=0;
        while(z--){
            num*=10;
            num+=7;
        }
//        cout<<num<<endl;
        x=pow(10,x);
        y=pow(10,y);
        ll xx=x/num;
        ll yy=y/num;
        xx*=num;
        yy*=num;
        ll gcd=__gcd(xx,yy);
        while(gcd>num){
            yy-=num;
            gcd=__gcd(xx,yy);
        }
//        gcd=__gcd(xx,yy);
//        while(__gcd(xx,yy)>num) yy-=num;
        cout<<xx<<" "<<yy<<endl;
    }
    return 0;
}

C - Yet Another Card Deck

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
const int N = 3e5 + 10;
using namespace std;

int dp[N];
vector<int>vp;
//vector<int>ans;

int main()
{
    ios::sync_with_stdio(0);
    int n,q;
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&dp[i]);
    for(int i=n;i>=1;i--) vp.pb(dp[i]);
    while(q--){
        int k;
        scanf("%d",&k);
        int pos;
        int len=vp.size();
        for(int i=len-1;i>0;i--){
            if(vp[i]==k){
                vp.erase(vp.begin()+i);
                pos=n-i;
                break;
            }
        }
        vp.pb(k);
//        ans.pb(pos);
        printf("%d ",pos);
    }
//    for(int i=0;i<(int)ans.size();i++){
//        if(i==0) cout<<ans[i];
//        else cout<<" "<<ans[i];
//    }
//    cout<<endl;
    return 0;
}

D - Min Cost String

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
const int N = 1e6 + 10;
using namespace std;

int dp[N];
string s;

//void solve(char l,char r){
//    for(int i=l-'a';i<=r-'a';i++){
//        for(int j=i-'a';j<=r-'a';j++){
//            s+=j+'a';
//            if(j!=r) s+=i+'a';
//        }
//    }
//}

void solve(char l,char r){
    for(auto i=l;i<=r;i++){
        for(auto j=i;j<=r;j++){
            s+=j;
            if(j!=r) s+=i;
        }
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    int k=m-1+'a';
    solve('a',k);
    int l=s.length();
    for(int i=0;i<n;i++){
        cout<<s[i%l];
    }
    cout<<endl;
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值