CF1305A Kuroni and the Gifts

题意

给定两个长度为 nn 的序列 a,ba, b,每个序列中没有相同元素,现在可以任意打乱 a,ba, b,使得任意 ai+bi(1in)a_i+b_i(1 \le i \le n) 不相同,多组测试。

解法

因为没有相同元素,考虑对 a,ba, b 都从小到大排序即可。这样任意 ai+bi>ai1+bi1a_i+b_i > a_{i-1}+b_{i-1}

代码:

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

const int N = 105;

int t;
set<int> a, b;

int main()
{
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d", &n);
        a.clear();
        b.clear();
        for (int i = 1; i <= n; i++) 
        {
            int x;
            scanf("%d", &x);
            a.insert(x);
        }
        for (int i = 1; i <= n; i++) 
        {
            int x;
            scanf("%d", &x);
            b.insert(x);
        }
        for (auto it = a.begin(); it != a.end(); ++it)
        {
            printf("%d ", *it);
        }
        puts("");
        for (auto it = b.begin(); it != b.end(); ++it)
        {
            printf("%d ", *it);
        }
        puts("");
    }
    return 0;
}
posted @   HappyBobb  阅读(3)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示