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. python文件流

    打开文件 文件的基本方法 迭代文件内容 打开文件 打开文件,可以使用自动导入的模块io中的函数open.函数open将文件名作为唯一必不可少的参数,并返回一个文件对象.如果只指定一个文件名,则获得一个 ...

  2. RabbitMQ详解(二)------消息通信的概念

    PS:近期在南宁出差,工作比较忙,所以更新会比较慢. 说到消息通信,可能我们首先会想到的是邮箱,QQ,微信,短信等等这些通信方式,这些通信方式都有发送者,接收者,还有一个中间存储离线消息的容器.但是这 ...

  3. Android so注入(inject)和Hook技术学习(一)

    以前对Android so的注入只是通过现有的框架,并没有去研究so注入原理,趁现在有时间正好拿出来研究一下. 首先来看注入流程.Android so的注入流程如下: attach到远程进程 -> ...

  4. Scala学习(九)---文件和正则表达式

    文件和正则表达式 摘要: 在本篇中,你将学习如何执行常用的文件处理任务,比如从文件中读取所有行或单词,或者读取包含数字的文件等.本篇的要点包括: 1. Source.fromFile(...).get ...

  5. 性能调优3:硬盘IO性能

    数据库系统严重依赖服务器的资源:CPU,内存和硬盘IO,通常情况下,内存是数据的读写性能最高的存储介质,但是,内存的价格昂贵,这使得系统能够配置的内存容量受到限制,不能大规模用于数据存储:并且内存是易 ...

  6. position fixed 相对于父级定位

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 使用 Markdown编辑

    作用: 学习笔记,整理日志, 发布日记,杂文,所见所想 撰写发布技术文稿(代码支持) 撰写发布学术论文(LaTeX 公式支持) sublime text3插件 输入 Shift + Ctrl + P, ...

  8. Linux sudoers

    xxx is not in the sudoers file.This incident will be reported.的解决方法 - xiaochaoyxc - 博客园http://www.cn ...

  9. java的编程习惯影响程序性能

    在Java程序中,性能问题的大部分原因并不在于Java语言,而是在于程序本身. 养成良好的编程习惯非常重要,能够显著地提升程序性能. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时 ...

  10. PropertyChangeSupport 监听器模式的应用

    PropertyChangeSupport 类实现的监听器功能 ,它是java jdk自带的一个类,用于监听某个对象属性的改变来触发相应信息,具体看代码介绍 import java.beans.Pro ...