Educational Codeforces Round 98 (Rated for Div. 2)

Educational Codeforces Round 98 (Rated for Div. 2)

A. Robot Program

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn=2e5+5;

void solve() {
    int x,y;
    cin>>x>>y;
    cout<<max(x,y)*2-(x!=y)<<"\n";
}

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

B. Toy Blocks

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn=2e5+5;

void solve() {
    int n,x,sum=0,max_=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>x,sum+=x,max_=max(max_,x);
    cout<<max(max_*(n-1)-sum,sum%(n-1)?n-1-sum%(n-1):0)<<"\n";
}

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

C. Two Brackets

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn=2e5+5;

stack<int >a,b;

void solve() {
    while (!a.empty()) a.pop();
    while (!b.empty()) b.pop();
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='(') a.push(1);
        if(s[i]=='[') b.push(1);
        if (s[i]==')'&&!a.empty()) sum++,a.pop();
        if (s[i]==']'&&!b.empty()) sum++,b.pop();
    }
    cout <<sum<<"\n";
}

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

D. Radio Towers

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=998244353;

int f[maxn];

void init(){
    f[0]=0;f[1]=1;
    for (int i = 2; i < maxn; ++i)
        f[i]=(f[i-1]+f[i-2])%mod;
}

int fastpow(int a,int n){
    int res=1,temp=a;
    while (n){
        if(n&1) res=res*temp%mod;
        temp=temp*temp%mod;
        n>>=1;
    }
    return res;
}

void solve() {
    int n;
    cin>>n;
    cout<<f[n]*fastpow(fastpow(2,n),mod-2)%mod;
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;init();
    while (_--) {
       solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值