B. Guess the Permutation

题目连接:

http://www.codeforces.com/contest/618/problem/B

Description

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

Sample Input

2

0 1

1 0

Sample Output

2 1

Hint

题意

给你一个n*n的矩阵,矩阵aij = min(si,sj) aii = 0

然后让你还原s数组,s数组是1-n的排列

题解:

如果某一行出现了n-1个1,那么说明这行一定是1

如果某一行出现了n-2个2,那么这一行一定是2

.....

然后就搞定了,如果某一行出现了n-i个i,那么这一行就是i

代码

#include<bits/stdc++.h>
using namespace std; int n;
int a[55][55];
int ans[55];
int vis[55];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(vis[j])continue;
int tot = 0;
for(int k=1;k<=n;k++)
{
if(a[j][k]==i)
tot++;
}
if(tot==n-i)
{
ans[j]=i;
vis[j]=1;
break;
}
}
}
for(int i=1;i<=n;i++)
printf("%d ",ans[i]);
printf("\n");
}

Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation 水题的更多相关文章

  1. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) A. Slime Combining 水题

    A. Slime Combining 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2768 Description Your frien ...

  2. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) F. Double Knapsack 鸽巢原理 构造

    F. Double Knapsack 题目连接: http://www.codeforces.com/contest/618/problem/F Description You are given t ...

  3. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) E. Robot Arm 线段树

    E. Robot Arm 题目连接: http://www.codeforces.com/contest/618/problem/E Description Roger is a robot. He ...

  4. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)

    现在水平真的不够.只能够做做水题 A. Slime Combining 题意:就是给n个1给你.两个相同的数可以合并成一个数,比如说有两个相同的v,合并后的值就是v+1 思路:直接模拟栈 #inclu ...

  5. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题

    A. Checking the Calendar 题目连接: http://codeforces.com/contest/724/problem/A Description You are given ...

  7. Codeforces Round #354 (Div. 2) A. Nicholas and Permutation 水题

    A. Nicholas and Permutation 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nichol ...

  8. Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题

    C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...

  9. Codeforces Round #294 (Div. 2)B - A and B and Compilation Errors 水题

    B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. 获取当前的 viewController

    - (UIViewController *)currentController {    UIViewController *result = nil;    UIWindow *window = [ ...

  2. 把两个DataTable连接起来,相当于Sql的Inner Join方法

    在C#中把两个DataTable连接起来,相当于Sql的Inner Join方法 作者:浪漫十一狼在下面的例子中实现了3个Join方法,其目的是把两个DataTable连接起来,相当于Sql的Inne ...

  3. 句柄(handle)

    < Back 句柄,在windows编程中用来标识: *.模块(module) *.任务(task) *.实例(instance) *.文件(file) *.内存块(block of memor ...

  4. git初步使用

    git初步使用 主要目的:使用代码控制工具,练习使用git 1.创建新项目 网址如下: https://github.com/kellyseeme?tab=repositories 注意每个人使用的名 ...

  5. ansible服务模块和组模块使用

    本篇文章主要是介绍ansible服务模块和组模块的使用. 主要模块为ansible service module和ansible group moudle,下面的内容均是通过实践得到,可以直接运行相关 ...

  6. jQuery hover demo

    先放效果图: 百度云下载地址:http://pan.baidu.com/s/1dDpn1Sl 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  7. 怎样下载完整的Spring包

    自从3.2版本以后,Spring不再提供包含所有库的文件下载了只有Sping自身的最基本库,所依赖的东西需要自己搞定首先, 这个链接 包含了Spring自身和所用到的所有东西   这个 是上述链接的说 ...

  8. cubieboard中使用py-kms与dnsmasq搭建局域网内全自动KMS激活环境

    众所周知,KMS激活方式是当前广大网民“试用”windows,office的最广泛的激活方式.几乎可以用于微软的全线产品. 但是在本机使用KMS类的激活工具总是有些不放心,一方面每隔180天都要重新激 ...

  9. DataGrid loadData loadFilter

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Cl ...

  10. iPhone 6/6 Plus 出现后,如何改进工作流以实现一份设计稿支持多个尺寸?

    iPhone 6/6 Plus 出现后,如何改进工作流以实现一份设计稿支持多个尺寸? 2014-12-05 09:33 编辑: suiling 分类:iOS开发 来源:知乎(pigtwo)  2 22 ...