Codeforces Round 971 (Div. 4) A~E

//A. Minimize!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 200000;

void solve() {
    int a,b;
    cin >>a>>b;
    cout<<abs(a-b)<<'\n';
}

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


//B. osu!mania

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 200000;

void solve() {
    int n;
    cin >>n;
    stack<int> stk;
    int j=n;
    while(j--){
        string s;
        cin >>s;
        int l=s.size();
        for(int i=0;i<l;i++){
            if(s[i]=='#'){
                stk.push(i+1);
                break;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<stk.top()<<' ';
        stk.pop();
    }cout<<'\n';
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
//C. The Legend of Freya the Frog

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    long long x, y, k;
    cin >> x >> y >> k;

    long long steps_x = (x + k - 1) / k;
    long long steps_y = (y + k - 1) / k;
    
    long long result;
    if (steps_x == steps_y) {
        result = steps_x + steps_y;
    } else {
        result = 2 * max(steps_x, steps_y) - 1;
        if(steps_x<steps_y)result++;
    }
    
    cout << result << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
//D. Satyam and Counting

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    int n;
    ll ans=0;
    cin >>n;
    vector<vector<int>> arr(2,vector<int>(n+1,0));
    for(int i=0,a,b;i<n;i++){
        cin >>a>>b;
        arr[b][a]=1;
    }
    for(int i=0;i<=n;i++){
        if(arr[0][i]&&arr[1][i]){
            ans+=n-2;
        }
        if(i>=2){
            if(arr[0][i]&&arr[0][i-2]&&arr[1][i-1])ans++;
            if(arr[1][i]&&arr[1][i-2]&&arr[0][i-1])ans++;
        }
    }cout<<ans<<'\n';
}

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

//E. Klee's SUPER DUPER LARGE Array!!!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    ll n, k;
    cin >> n >> k;
    
    ll l = k;
    ll r = k + n - 1;
    ll ans = LLONG_MAX;

    while (l <= r) {
        ll m = (l + r) / 2;
        ll ml = (k+m)*(m-k+1) / 2;
        ll mr = (m+1+k+n-1)*(n-(m-k+1)) / 2;

        ll diff = abs(ml - mr);
        ans = min(ans, diff);

        if (ml < mr) {
            l = m + 1;
        } else if (ml > mr) {
            r = m - 1;
        } else {
            ans = 0;
            break;
        }
    }

    cout << ans << '\n';
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值