CF1790C Premutation
https://codeforces.com/problemset/problem/1790/C
题目大意:有一个序列,我们将对他进行这样的一个操作,比如我们现在有3,1,4,2,这样一个序列,那么我们在第i次将删去第i个数,比如第一次将3去除并得到一个子序列1,4,2,以此类推我们可以得到四个子序列如下:1,4,2 3,4,2 3,1,2 3,1,4。而题目要求是我们需要对其给出子序列来进行求解,求出原序列。
通过观察不难得出,第一个数会且只会被删去一个,所以换一种说法是,第一个数在第一个位置至少出现了两次,因此我们可以去对比前3个子序列,他们中出现了两次的第一个数就是原序列第一个数,而接下的子序列中那些第一个数不是他的就是剩下的全部数,我们只要将他全部打印一遍就行
#include<iostream>
#include<vector>
#include<utility>
#include<map>
using namespace std;
int a[110][110];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 0; i <= n-1; i++)
{
for (int j = 0; j < n-1; j++)
{
cin >> a[i][j];
}
}
int res=a[0][0];
if (a[0][0] == a[1][0])
{
res = a[0][0];
}
else
{
res = a[2][0];
}
cout << res << " ";
for (int i = 0; i <= n-1; i++)
{
if (a[i][0] != res)
{
for (int j = 0; j < n - 1; j++)
{
cout << a[i][j] << " ";
}
}
}
cout << endl;
}
return 0;
}