Codeforce-Ozon Tech Challenge 2020-A. Kuroni and the Gifts
the i-th necklace has a brightness ai, where all the ai are pairwise distinct (i.e. all ai are different), the i-th bracelet has a brightness bi, where all the bi are pairwise distinct (i.e. all bi are different). Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the i-th daughter receives a necklace with brightness xi and a bracelet with brightness yi, then the sums xi+yi should be pairwise distinct. Help Kuroni to distribute the gifts.
For example, if the brightnesses are a=[1,7,5] and b=[6,1,2], then we may distribute the gifts as follows:
Give the third necklace and the first bracelet to the first daughter, for a total brightness of a3+b1=11. Give the first necklace and the third bracelet to the second daughter, for a total brightness of a1+b3=3. Give the second necklace and the second bracelet to the third daughter, for a total brightness of a2+b2=8. Here is an example of an invalid distribution:
Give the first necklace and the first bracelet to the first daughter, for a total brightness of a1+b1=7. Give the second necklace and the second bracelet to the second daughter, for a total brightness of a2+b2=8. Give the third necklace and the third bracelet to the third daughter, for a total brightness of a3+b3=7. This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don’t make them this upset!
Input The input consists of multiple test cases. The first line contains an integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤100) — the number of daughters, necklaces and bracelets.
The second line of each test case contains n distinct integers a1,a2,…,an (1≤ai≤1000) — the brightnesses of the necklaces.
The third line of each test case contains n distinct integers b1,b2,…,bn (1≤bi≤1000) — the brightnesses of the bracelets.
Output For each test case, print a line containing n integers x1,x2,…,xn, representing that the i-th daughter receives a necklace with brightness xi. In the next line print n integers y1,y2,…,yn, representing that the i-th daughter receives a bracelet with brightness yi.
The sums x1+y1,x2+y2,…,xn+yn should all be distinct. The numbers x1,…,xn should be equal to the numbers a1,…,an in some order, and the numbers y1,…,yn should be equal to the numbers b1,…,bn in some order.
It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.
Example inputCopy 2 3 1 8 5 8 4 5 3 1 7 5 6 1 2 outputCopy 1 8 5 8 4 5 5 1 7 6 2 1 Note In the first test case, it is enough to give the i-th necklace and the i-th bracelet to the i-th daughter. The corresponding sums are 1+8=9, 8+4=12, and 5+5=10.
The second test case is described in the statement.
使每个a+b不同,因为每个a不同,b同所以不会有,ai+bi=aj+bj。只有ai<aj且bi>bj或者反过来,显然
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int a[N], b[N];
int main()
{
int n, t;
read(t);
while (t--)
{
read(n);
rep(0, n, i) read(a[i]);
rep(0, n, i) read(b[i]);
sort(a, a + n);
sort(b, b + n);
rep(0, n, i) wi(a[i]);
P;
rep(0, n, i) wi(b[i]);
P;
}
}
- mvn编译的时候一个破错误,google只有3个结果maven : Failed to install metadata project Could not parse metadata maven-
- 读书|《Mastering Machine Learning with Python in Six Steps》
- 几种简单的文本数据预处理方法
- Fiddler中显示IP方法
- readlink: command not found 解决方案
- Java 并发编程系列: CountDownLatch (上厕所的案例)
- 详解ANGULAR2组件中的变化检测机制(对比ANGULAR1的脏检测)
- 如何快速查看github代码库中第一次commit的记录
- 更换包管理工具npm为yarn
- 【精选】使用Cryptory分析影响加密货币价格的因素(区块链系列3)
- React -- 组件间通信
- 图片和视频防盗链简单介绍
- 对比cp和scp命令 将数据从一台linux服务器复制到另一台linux服务器
- laravel—用Migration的操作数据库
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法