0529A题题解

A - Kuroni and the Gifts

原题:
Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets:

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
Input
2
3
1 8 5
8 4 5
3
1 7 5
6 1 2
Output
1 8 5
8 4 5
5 1 7
6 2 1
题意:
父亲给他的孩子们买了两种可以发光的礼物,分别有不同的发光程度,希望每个女儿的搭配这2个东西所呈现的发光程度不同(翻译不好见谅)要求我们分配好这两种物品。
思路:
我们可以通过创建两个数组来存储这两种东西的发光值,考虑到将两种数组先排好序他们所对应的和也是按升序排列的结果,一定不会相同。
代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t,n,a[100],b[100];
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		} 
		for(int i = 0; i < n; i++) {
		cin >> b[i];}
		sort(a,a+n);
		sort(b,b+n);
		for(int i = 0; i < n; i++){
			cout<<a[i]<<" ";
		}
		cout<<endl;
		for(int i = 0; i < n; i++){
			cout<<b[i]<<" ";
		}
		cout<<endl;
	} 
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
国赛目一般来源于科学与工程技术、人文与社会科学等领域经过适当简化加工的实际问。参赛者不需要预先掌握深入的专门知识,只需要学过高等学校的数学基础课程。对于解思路,可以根据目要求进行以下步骤来完成建模和求解: 1. 理解目:仔细阅读目,理解问的背景和要求。注意提取关键信息,明确问的目标和约束条件。 2. 建立数学模型:根据目的描述和要求,将实际问转化为数学模型。可以使用已知的数学理论、公式和方法,结合问的特点进行建模。根据问类型,可以将问归类为分类问、优化问、预测问或评价问。 3. 求解模型:根据建立的数学模型,使用适当的数学工具和方法进行求解。可能需要进行数值计算、优化算法或统计分析等操作,以得到问的解答。 4. 分析和检验结果:对求解结果进行分析和检验,验证其合理性和正确性。可以通过对比实际数据或进行敏感性分析来评估模型的准确性和可靠性。 5. 模型的改进:根据对结果的分析和检验,对模型进行改进。可以尝试不同的假设或调整参数,以提高模型的性能和适应性。 综上所述,解思路主要包括理解目、建立数学模型、求解模型、分析和检验结果以及模型的改进。具体的解思路会根据不同的目和问类型有所差异,建议参赛者根据具体目要求和自身的数学知识经验,灵活运用数学方法和工具,进行问的建模和求解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值