【CodeForces 618B】Guess the Permutation(水题)

来源:互联网 发布:工艺流程软件软件 编辑:程序博客网 时间:2024/04/28 00:06

Description

Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n.

Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

Input

The first line of the input will contain a single integer n (2 ≤ n ≤ 50).

The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It’s guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given.

Output

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.

Sample Input

Input

2
0 1
1 0

Output

2 1

Input

5
0 2 2 1 2
2 0 4 1 3
2 4 0 1 3
1 1 1 0 1
2 3 3 1 0

Output

2 5 4 1 3

题目大意

给你一个n,表示接下来的矩阵有5*5,矩阵中的每一个元素(i,j)都是通过长度为n的整数序列a1,a2,a3,a4,a5中的min(ai,aj)得来的,当i==j时默认(i,j)=0,现在给你这个n*n的矩阵求这个长度为n的整数序列。

思路

这是一题找规律题,可以发现当j确定看i时,比如第一列,它表示每一个点ai和a1中小的那一个,那么我a1就应该是第一列中最大的一个数或者最大的一个数加1,由此我们就可以得到每一ai了,但是为了保险最好在跑一遍1~n的循环找有没有两个相等的ai,如果有将其中一个加1.

代码

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <set> using namespace std; const int maxn=50+5; int map[maxn][maxn],n,ans[maxn]; int main() {    while(~scanf("%d",&n))    {        set<int> q;        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)            {                scanf("%d",&map[i][j]);            }        for(int i=1;i<=n;i++)        {            for(int j=1;j<=n;j++)            {                ans[i]=max(ans[i],map[j][i]);            }        }        for(int i=1;i<=n;i++)            for(int j=i+1;j<=n;j++)            {                if(ans[i]==ans[j]) ans[i]++;            }        for(int i=1;i<=n;i++)        {            if(i==1) printf("%d",ans[i]);            else printf(" %d",ans[i]);        }        printf("\n");    }       return 0; }
0 0
原创粉丝点击