2024牛客寒假算法基础集训营3【难题详解】

K. 智乃的“黑红树”

队列模拟

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define no cout<<"No"<<endl
#define yes cout<<"Yes"<<endl
#define endl '\n'
// #define x first
// #define y second
typedef pair<int,int> PII;
const int N=200010;
const int mod=998244353;
const int INF=0x3f3f3f3f;
void solve(){
    int a,b;cin>>a>>b;
    if(a%2==0||b&1){
        no;
        return;
    }
    if(a*2<b||b*2<(a-1)){
        no;
        return;
    }
    yes;
    a--;a/=2;b/=2;
    queue<int>q;q.push(1);
    unordered_map<int,int>mp;mp[1]=1;
    int idx=2;
    do{
        auto t=q.front();
        q.pop();
        if(mp[t]==1){
            if(b){
                cout<<idx<<' '<<idx+1<<endl;
                q.push(idx);mp[idx]=2;
                q.push(idx+1);mp[idx+1]=2;
                idx+=2;
                b--;
            }
            else cout<<-1<<' '<<-1<<endl;
        }
        if(mp[t]==2){
            if(a){
                cout<<idx<<' '<<idx+1<<endl;
                q.push(idx);mp[idx]=1;
                q.push(idx+1);mp[idx+1]=1;
                idx+=2;
                a--;
            }
            else cout<<-1<<' '<<-1<<endl;
        }
    }while(q.size());
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _=1;
    cin>>_;
    while(_--)solve();
    return 0;
}

J. 智乃的相亲活动

H. 智乃的比较函数(normal version)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值