Kuroni and the Gifts(补题)

Kuroni and the Gifts

题目描述:

Kuroni has nn daughters. As gifts for them, he bought nn necklaces and nn bracelets:

the ii-th necklace has a brightness aiai, where all the aiai are pairwise distinct (i.e. all aiai are different),
the ii-th bracelet has a brightness bibi, where all the bibi are pairwise distinct (i.e. all bibi 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 ii-th daughter receives a necklace with brightness xixi and a bracelet with brightness yiyi, then the sums xi+yixi+yi should be pairwise distinct. Help Kuroni to distribute the gifts.

For example, if the brightnesses are a=[1,7,5]a=[1,7,5] and b=[6,1,2]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=11a3+b1=11.
Give the first necklace and the third bracelet to the second daughter, for a total brightness of a1+b3=3a1+b3=3.
Give the second necklace and the second bracelet to the third daughter, for a total brightness of a2+b2=8a2+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=7a1+b1=7.
Give the second necklace and the second bracelet to the second daughter, for a total brightness of a2+b2=8a2+b2=8.
Give the third necklace and the third bracelet to the third daughter, for a total brightness of a3+b3=7a3+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 tt (1≤t≤1001≤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 nn (1≤n≤1001≤n≤100) — the number of daughters, necklaces and bracelets.

The second line of each test case contains nn distinct integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000) — the brightnesses of the necklaces.

The third line of each test case contains nn distinct integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤10001≤bi≤1000) — the brightnesses of the bracelets.

Output:

For each test case, print a line containing nn integers x1,x2,…,xnx1,x2,…,xn, representing that the ii-th daughter receives a necklace with brightness xixi. In the next line print nn integers y1,y2,…,yny1,y2,…,yn, representing that the ii-th daughter receives a bracelet with brightness yiyi.

The sums x1+y1,x2+y2,…,xn+ynx1+y1,x2+y2,…,xn+yn should all be distinct. The numbers x1,…,xnx1,…,xn should be equal to the numbers a1,…,ana1,…,an in some order, and the numbers y1,…,yny1,…,yn should be equal to the numbers b1,…,bnb1,…,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.

Sample Input:

2
3
1 8 5
8 4 5
3
1 7 5
6 1 2

Sample Output:

1 8 5
8 4 5
5 1 7
6 2 1

题目分析:

一位好父亲十分爱自己的女儿,他为他们买了礼物,分别是2件带有发光的物品(翻译不好见谅),并且发光的值不一样,他希望每个女儿的搭配这2个东西所呈现的发光值不一样,题目输入T(测试样例),输入N(所买的每一件件物品的数量),接下来分别是2件的物品下标所对应的发光值,聪明的你要如何搭配才能满足这位充满父爱的好父亲。

思路分析:

直接将2件物品的发光值用Sort从小到大排序,然后直接输出就行了。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int num,t;
	int a[2][1000];
	scanf("%d",&t);
	while(t--)
	{
	scanf("%d",&num);
	for(int j=0;j<2;j++)
	for(int i=0;i<num;i++)
	{
		scanf("%d",&a[j][i]);
	}
	sort(a[0],a[0]+num);
	sort(a[1],a[1]+num);
	for(int j=0;j<2;j++)
	{
		for(int i=0;i<num;i++)
		{
			printf(i!=num-1?"%d ":"%d\n",a[j][i]);
		}
	}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值