Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)--B. Guess the Permutation

B. Guess the Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 be0. 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 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
大体题意:
起床又读了一遍题,则彻底搞明白(第一次打比较紧张。。)
给你一个矩阵,保证主对角线上全是0,并且对称(就是斜着对称),存在另一个从1-n数组(p[1],p[2]....p[n]),矩阵上的数满足一个规律a[i][j] = min (p[i],p[j]),因为下标是两个变量i,j,放在整个矩阵里研究比较麻烦不好分析,所以先确保一个变量不变,比如说i不变,让j变,这就是一行一行的研究,仔细想想就明白了,一行里肯定有一个0,因为一个数组和自己比较肯定有相同的一个,然后p[i]就是没一行里出现次数最多的数,如果这一行里每个数字都是出现一次,那么肯定n和n-1了!
输出p数组即可!

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<sstream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1000 + 10;
const int maxt = 100 + 10;
const double eps = 1e-8;

int main()
{
    ios::sync_with_stdio(false);
    int n,num;
    int rec[maxt][maxt];
    while(cin >> n){
        memset(rec,0,sizeof(rec));
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j){
                cin >> num;
                rec[i][num]++;
            }
        int sum = 0;
        for (int k = 0; k < n; ++k){
            int maxx=0,key=0;
            for (int i = 1; i <= n; ++i)if (rec[k][i]>maxx){maxx=rec[k][i];key=i;}
            if (maxx > 1)cout << key << " ";
            else {
                if (sum)cout << n << " ";
                else cout << n-1 << " ";
                sum++;
            }
        }
        cout << endl;
    }
    return 0;
}


你可能感兴趣的:(C语言,codeforces)