Guess the Permutation

CodeForces - 618B

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, jbetween 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.

Examples

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 be {1, 2} or {2, 1}.

In the second case, another possible answer is {2, 4, 5, 1, 3}.

sol:容易发现对于有且仅有一个序列只有1,有且仅有2个序列只有1,2······

这样就可以对每行维护一个前缀和表示该行数字1~i的数字出现的次数和,然后从1到n一个个数字填过去即可

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
int a[N][N],Ges[N][N];
int Ans[N];
bool Arr[N];
int main()
{
int i,j;
R(n);
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
R(a[i][j]);
Ges[i][a[i][j]]++;
}
for(j=;j<=n;j++) Ges[i][j]=Ges[i][j-]+Ges[i][j];
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++) if((Ges[j][i]==n-)&&(!Arr[j]))
{
Ans[j]=i;
Arr[j]=;
break;
}
}
for(i=;i<=n;i++) W(Ans[i]);
return ;
}
/*
input
2
0 1
1 0
output
2 1 或 1 2 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 或 2 4 5 1 3
*/

codeforces618B的更多相关文章

随机推荐

  1. eclipse svn 删除不了项目,合并不了问题

    window/preferences  下  Teme  >svn  svn接口选择跟删除不了有关 但是合并 需要选择 JavaHl svn 服务端 1.8 eclipse选则 http://s ...

  2. 有关Web常用字体的研究?

    Windows自带字体: 黑体:SimHei 宋体:SimSun 新宋体:NSimSun 仿宋:FangSong 楷体:KaiTi 仿宋GB2312:FangSongGB2312 楷体GB2312:K ...

  3. Java 多线程(六)之Java内存模型

    目录 1. 并发编程的两个问题 2 CPU 缓存模型 2.1 CPU 和 主存 2.2 CPU Cache 2.3 CPU如何通过 Cache 与 主内存交互 2.4 CPU 缓存一致性问题 3 Ja ...

  4. Item 25: 对右值引用使用std::move,对universal引用则使用std::forward

    本文翻译自<effective modern C++>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 右值引用只能绑定那些有资格被move的对象上去.如 ...

  5. Quartz.NET 任务调度新教程

    https://www.cnblogs.com/yscit/p/10393867.html

  6. ASP.NET MVC5+EF6+EasyUI 仓库管理系统

    简介 此系统是在框架基础上叠加的仓库系统功能,同样是开源的,可以用于简单的仓库管理,您也可以在此基础上继续开发与完善! 仓库的框架功能会随着框架的升级而同样升级,仓库管理售价1666,已经购买过框架的 ...

  7. 二维数组中的查找问题--剑指offer面试题3

    题目:在一个二维数组中,对每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. // 二维数组中的查找 ...

  8. Hadoop生态的配置

    网盘下载地址 链接: https://pan.baidu.com/s/19qWnP6LQ-cHVrvT0o1jTMg 密码: 44hs Hadoop伪分布式配置  Hadoop 可以在单节点上以伪分布 ...

  9. 1 Expression of Possiblity

    Expression of possibility Probably     Perhaps There's a change(that) It's very likly(that) It's pos ...

  10. POI解析Excel代码

    // 批量区域数据导入 @Action(value = "area_batchImport") public String batchImport() throws IOExcep ...