C. Pair Programming-Codeforces Round #731 (Div. 3)

本文介绍了一道编程问题,两位程序员Monocarp和Polycarp合作编写代码,他们各自按照特定顺序修改文件。任务是找到一个共同的正确操作序列,确保新加入的行和改动均正确。通过实例解析了如何解决这个问题,包括检查文件初始状态和操作顺序对最终结果的影响。
摘要由CSDN通过智能技术生成

原文链接Problem - C - Codeforces

C. Pair Programming

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.

It's known that they have worked together on the same file for n+mn+m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already kk lines written in the file.

Every minute exactly one of them does one of two actions: adds a new line to the end of the file or changes one of its lines.

Monocarp worked in total for nn minutes and performed the sequence of actions [a1,a2,…,an][a1,a2,…,an]. If ai=0ai=0, then he adds a new line to the end of the file. If ai>0ai>0, then he changes the line with the number aiai. Monocarp performed actions strictly in this order: a1a1, then a2a2, ..., anan.

Polycarp worked in total for mm minutes and performed the sequence of actions [b1,b2,…,bm][b1,b2,…,bm]. If bj=0bj=0, then he adds a new line to the end of the file. If bj>0bj>0, then he changes the line with the number bjbj. Polycarp performed actions strictly in this order: b1b1, then b2b2, ..., bmbm.

Restore their common sequence of actions of length n+mn+m such that all actions would be correct — there should be no changes to lines that do not yet exist. Keep in mind that in the common sequence Monocarp's actions should form the subsequence [a1,a2,…,an][a1,a2,…,an] and Polycarp's — subsequence [b1,b2,…,bm][b1,b2,…,bm]. They can replace each other at the computer any number of times.

Let's look at an example. Suppose k=3k=3. Monocarp first changed the line with the number 22 and then added a new line (thus, n=2,a=[2,0]n=2,a=[2,0]). Polycarp first added a new line and then changed the line with the number 55 (thus, m=2,b=[0,5]m=2,b=[0,5]).

Since the initial length of the file was 33, in order for Polycarp to change line number 55 two new lines must be added beforehand. Examples of correct sequences of changes, in this case, would be [0,2,0,5][0,2,0,5] and [2,0,0,5][2,0,0,5]. Changes [0,0,5,2][0,0,5,2] (wrong order of actions) and [0,5,2,0][0,5,2,0] (line 55 cannot be edited yet) are not correct.

Input

The first line contains an integer tt (1≤t≤10001≤t≤1000). Then tt test cases follow. Before each test case, there is an empty line.

Each test case contains three lines. The first line contains three integers kk, nn, mm (0≤k≤1000≤k≤100, 1≤n,m≤1001≤n,m≤100) — the initial number of lines in file and lengths of Monocarp's and Polycarp's sequences of changes respectively.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤3000≤ai≤300).

The third line contains mm integers b1,b2,…,bmb1,b2,…,bm (0≤bj≤3000≤bj≤300).

Output

For each test case print any correct common sequence of Monocarp's and Polycarp's actions of length n+mn+m or -1 if such sequence doesn't exist.

Example

input

Copy

5

3 2 2
2 0
0 5

4 3 2
2 0 5
0 6

0 2 2
1 0
2 3

5 4 4
6 0 8 0
0 7 0 9

5 4 1
8 7 8 0
0

output

Copy

2 0 0 5 
0 2 0 6 5 
-1
0 6 0 7 0 8 0 9
-1

---------------------------------------------------------------------------------------------------------------------------------

每次先抓住一个扩展,一个不能扩展就扩展另一个。两个都不能扩展时,显然就不满足条件

首先,对于一个确定的nowk,凡是0或者比它小的,扩展掉没有任何副作用,每次循环让两者都前进到大于nowk的地方,这时每组只能仰仗另一组的扩展来增加nowk,当双方互相“仰仗”时,显然无法扩展。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
# include<map>
# include<iomanip>
# include<vector>
# pragma optimize(2)
using namespace std;
typedef long long int ll;
int a[110],b[110];
int ans[110];
int len;
int main ()
{
    int t;
    cin>>t;

    while(t--)
    {
        int k,n,m;
        cin>>k>>n>>m;
        len=0;
        int nowk=k;

        for(int i=1; i<=n; i++)
            cin>>a[i];


        for(int i=1; i<=m; i++)
            cin>>b[i];



        int left1=1,left2=1,flag=0;

        while(left1<=n||left2<=m)
        {

            int preleft1=left1;
            int preleft2=left2;

            while(a[left1]<=nowk&&left1<=n)
            {
                ans[len]=a[left1];
                if(a[left1]==0)
                    nowk++;
                len++;

                left1++;
            }


            while(b[left2]<=nowk&&left2<=m)
            {
                ans[len]=b[left2];
                len++;
                if(b[left2]==0)
                    nowk++;

                left2++;
            }

            if(preleft1==left1&&left2==preleft2)
            {
                flag=1;
                break;
            }

        }

        if(flag)
        {
            cout<<-1<<'\n';
        }

        else
        {
            for(int i=0; i<len; i++)
            {
                cout<<ans[i]<<" ";
            }

            cout<<'\n';
        }

    }


    return 0;
}

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值