B. Guess the permutation
Bob has a permutation of integers from1 toN. Denote this permutation as p . The i -th element of p will be denoted As p i . For all pairs of distinct integers i , J between 1 and N , he wrote the Number a i , j = min ( p I , P J ). He writes a i , i = 0 for All Integer i from 1 to n .
Bob gave you all the values of ai, J so he wrote down. Your job is to reconstruct any permutation that could has generated these values. The input would be formed, so, it is guaranteed, that there are at least one solution, is consistent with the Informat Ion given.
Input
The first line of the input would contain a single integer n (2≤ n ≤50).
The next n lines would contain the values of ai, J. The J-th number on the I-th line would represent ai, j . The i-th number on the I-th line would be0. It ' s guaranteed that ai, j = aJ, i And there are at least one solution consistent with the information given.
Output
Print n space separated integers, which represents a permutation that could has generated these values. If There is multiple possible solutions, print any of them.
Sample Test (s) 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
Note
In the first case, the answer can is {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}.
/* Find the position of the number I, the number of the first row is not larger than its number, the line number is its location, note the mark on the line * *
#include <cstdio>#include<cstring>#include<map>#include<stack>#include<iostream>#include<algorithm>using namespacestd;inta[ -][ -],p[ -];BOOLvis[ -];intMain () {intN; scanf ("%d",&N); for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) scanf ("%d",&A[i][j]); for(intI=1; i<=n;i++) { intJ; for(j=1; j<=n;j++) { intK; for(k=1; k<=n;k++) if(A[j][k]>i) Break; if(k==n+1&&!VIS[J]) Break; } Vis[j]=1; P[J]=i; } for(intI=1; i<=n;i++) printf ("%d", P[i]); return 0;}
Codeforces Wunder Fund Round (div. 1 + div. 2 combined) B Guess the permutation