codeforces618B
Guess the Permutation
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
2
0 1
1 0
2 1
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
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的更多相关文章
随机推荐
- java 加密 解密 Illegal key size
java.security.InvalidKeyException: Illegal key size 今天遇到一个奇怪的问题. 自己做的加签验签功能已经没有问题了,本地测试通过,同事放到服务器上 ...
- (通用版)salesforce中soql及sosl的伪‘Like’模糊检索
salesforce里有soql.sosl两种查询语法,soql针对模糊搜索也有‘like’关键字,然而只能针对其自带字段如:Name.Id:对于自定义添加的字段如:Message__c.Note__ ...
- 解决win7 win10上网卡慢问题
在管理员身份运行CMD命令行,然后输入netsh interface tcp set global autotuninglevel=disable 即可.
- Linux 下RPM打包制作流程
原文地址:https://www.cnblogs.com/postgres/p/5726339.html 开始前的准备 安装rpmbuild软件包 yum -y install rpm-build 生 ...
- SQLServer 存储过程+定时任务发邮件
SQLServer 代理发邮件需要开启SQL Server 代理服务器,然后,在[管理]-[数据库邮件]中,右键点击配置数据库邮件. 我用的是腾讯的企业邮箱,个人的163邮箱略微不同.下图是相关邮件的 ...
- 1003: [ZJOI2006]物流运输 = DP+SBFA
题意就是告诉你有n个点,e条边,m天,每天都会从起点到终点走一次最短路,但是有些点在某些时间段是不可走的,因此在某些天需要改变路径,每次改变路径的成本是K,总成本=n天运输路线长度之和+K*改变运输路 ...
- Python—time模块介绍
time 模块 在平常的代码中,我们常常需要与时间打交道.在Python中,常用的与时间处理有关的模块就包括:time,datetime,下面来介绍time模块. 在开始之前,首先要说明几点: 一.在 ...
- eclipse如何添加web dynamic project
很多eclipse版本是不能直接新建web dynamic project的,需要从网上找插件或更新. 比较方便的是在Help → Install-New-Software,点击add按钮,在Loca ...
- Python_面向对象基础
概念 类 一类抽象的事物,是描述了一类事物有哪些属性或者行为,但不是具体——模子. 实例 一个依托于类的规范存在的,被赋予了具体属性值的实际存在的物体. 对象 就是实例,实例的另外一个名称,相当于别名 ...
- Linux下破解pycharm
1.下载 https://pan.baidu.com/s/119UO4SGIEW_cxf0LmZzx3w 并将 JetbrainsCrack-3.1-release-enc.jar 放置到 pycha ...