codeforces Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B Guess the Permutation
2016-01-30 12:45
465 查看
B. 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, 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 be0. 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 test(s)
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}.
/*找第i个数的位置,第i个数所在的那一行肯定不会有比它大的数,行号就是它的位置,注意标记就行了*/ #include<cstdio> #include<cstring> #include<map> #include<stack> #include<iostream> #include<algorithm> using namespace std; int a[55][55],p[55]; bool vis[55]; int main() { int n; 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++) { int j; for(j=1;j<=n;j++) { int k; for(k=1;k<=n;k++) if(a[j][k]>i)break; if(k==n+1&&!vis[j])break; } vis[j]=1; p[j]=i; } for(int i=1;i<=n;i++) printf("%d ",p[i]); return 0; }
相关文章推荐
- solr5.4.1 quick start
- MAC系统下apktool和dex2jar和jd-Gui的安装
- cf#Wunder Fund Round 2016 -B- Guess the Permutation-构造-乱搞
- UIScrollView
- [Leetcode]Longest Increasing Subsequence
- tkinter的GUI设计:界面与逻辑分离(三)-- 多页面
- hdu 2192 MagicBuilding
- 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
- 面试必备:String,StringBuffer,StringBuilder区别
- 推荐两个界面原型设计工具--GUIDesignStudio 和 Mockups For Desktop
- Druid Monitor监控JavaSE和JavaWeb
- The Java™ Tutorials — Generics :Guidelines for Wildcard Use 通配符使用指南
- iOS开发 贝塞尔曲线UIBezierPath
- 《iOS Human Interface Guidelines》——Edit Menu
- 实例讲解iOS应用开发中使用UITableView创建自定义表格
- HDU 1005:Number Sequence
- ArduinoYun教程之配置Arduino Yun环境
- iOS个人整理15-UIImagePickerController,照片选择器
- PHP - PHP Error[2]: Error while sending QUERY packet. PID=*