【CodeForces 618B】Guess the Permutation(水题)
来源:互联网 发布:工艺流程软件软件 编辑:程序博客网 时间:2024/04/28 00:06
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
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
题目大意
给你一个n,表示接下来的矩阵有5*5,矩阵中的每一个元素(i,j)都是通过长度为n的整数序列a1,a2,a3,a4,a5中的min(ai,aj)得来的,当i==j时默认(i,j)=0,现在给你这个n*n的矩阵求这个长度为n的整数序列。
思路
这是一题找规律题,可以发现当j确定看i时,比如第一列,它表示每一个点ai和a1中小的那一个,那么我a1就应该是第一列中最大的一个数或者最大的一个数加1,由此我们就可以得到每一ai了,但是为了保险最好在跑一遍1~n的循环找有没有两个相等的ai,如果有将其中一个加1.
代码
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <set> using namespace std; const int maxn=50+5; int map[maxn][maxn],n,ans[maxn]; int main() { while(~scanf("%d",&n)) { set<int> q; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%d",&map[i][j]); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { ans[i]=max(ans[i],map[j][i]); } } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(ans[i]==ans[j]) ans[i]++; } for(int i=1;i<=n;i++) { if(i==1) printf("%d",ans[i]); else printf(" %d",ans[i]); } printf("\n"); } return 0; }
- 【CodeForces 618B】Guess the Permutation(水题)
- Codeforces 618B Guess the Permutation
- CodeForces 618B-Guess the Permutation【搜索】
- CodeForces 618 B. Guess the Permutation(水~)
- CodeForces - 618B Guess the Permutation (模拟)
- Codeforces--618B--Guess the Permutation(规律)
- B. Guess the Permutation
- CF618B - Guess the Permutation
- Guess the Permutation
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)-B. Guess the Permutation(模拟)
- Wunder Fund Round 2016 B. Guess the Permutation
- codeforces B. Restoration of the Permutation
- C. Guess the Array(codeforces)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)--B. Guess the Permutation
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation
- cf#Wunder Fund Round 2016 -B- Guess the Permutation-构造-乱搞
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation
- codeforces B. Permutation
- SQLZOO(SELECT within SELECT Tutorial)Writeup
- I00001 杨辉三角
- APP上架审核被拒(新增2016.04)
- 嵌套json解析
- 使用ABBYY FineReader 12的那些心得体会
- 【CodeForces 618B】Guess the Permutation(水题)
- SOLR安装简单配置
- 缺少动态链接库: libthrift-0.9.3.so: cannot open shared object file: No such file or directory
- 关于解耦 分布式部署 架构 设计模式的疑问
- oracle的常用函数 instr() 和substr()函数
- 关于<s:iterator/>标签
- JAVA--备忘录模式(Memento)--设计模式十九
- C#中params关键字的作用理解
- Cookie(甜饼)