Educational Codeforces Round 98 (Rated for Div. 2)

Educational Codeforces Round 98 (Rated for Div. 2)

传送门(点击传送

之后会补全题意和思路

A. Robot Program

题意:
  有一个机器人在(0,0)位置,你可向上、向下、向左、向右移动一个单位,也可以待在原地,不能连着两次向同一个方向移动,问从(0,0)到(x,y)需要多少步。( t 组数据)

思路:
  分为两个步骤,第一个步骤先从(0,0)移动到(min(x,y),min(x,y)),然后第二个步骤再朝着(x,y)曲折前进,通过调整第一个步骤起始是向上或者向右让两个步骤中间不用多余的等待。

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t,x,y;
    cin>>t;
    while(t--){
    
    
        cin>>x>>y;
        if(x==y){
    
    
            cout<<x+y<<endl;
        }else{
    
    
            cout<<max(x,y)*2-1<<endl;
        }
    }
    return 0;
}

B. Toy Blocks

题意:

思路:

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t,n;
    cin>>t;
    while(t--){
    
    
        ll maxn=0,get_num,sum=0;
        cin>>n;
        for(int i=1;i<=n;i++){
    
    
            cin>>get_num;
            sum+=get_num;
            maxn=max(maxn,get_num);
        }
        if(sum<=(n-1)*maxn){
    
    
            cout<<(n-1)*maxn-sum<<endl;
        }else{
    
    
            ll cha=sum-(n-1)*maxn,need;
            if(cha%(n-1)==0) need=cha/(n-1);
            else need=cha/(n-1)+1;
            cout<<(n-1)*(maxn+need)-sum<<endl;
        }
    }
    return 0;
}

C. Two Brackets

题意:

思路:

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;
    string s;
    cin>>t;
    while(t--){
    
    
        cin>>s;
        int ans=0,k1=0,k2=0;//k1->()   k2->[]
        for(auto &x:s){
    
    
            if(x=='('){
    
    
                k1++;
            }else if(x=='['){
    
    
                k2++;
            }else if(x==')' && k1>0){
    
    
                k1--;ans++;
            }else if(x==']' && k2>0){
    
    
                k2--;ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

D. Radio Towers

题意:

思路:

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const ll mod=998244353;
ll dp[maxn];
ll binpow(ll a, ll b, ll m) {
    
    
    a %= m;
    ll res = 1;
    while (b > 0) {
    
    
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    dp[1]=1;dp[2]=1;
    for(int i=3;i<=n;i++){
    
    
        dp[i]=(dp[i-2]+dp[i-1])%mod;
    }
    cout<<dp[n]*binpow(binpow(2,n,mod),mod-2,mod)%mod<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/blaction/article/details/110292891