CF618B - Guess the Permutation
来源:互联网 发布:艾克里里の淘宝店 编辑:程序博客网 时间:2024/05/10 17:56
题目大意:有n个数1~n的全排列,给你一个n*n的矩阵,Aij表示第i位和第j位中较小的哪一个,对角线是0,求原数列。
这么考虑,首先1与其他比较肯定1是最小的,那一行肯定除了对角线的0,其他全是1。这样,找到1的位置。接下来,把矩阵中所有1变成2,找到的那一行标记为“占用”,然后去找“非占用”的行中除了0全是2的那一行,确定2的位置,以此类推。
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<cmath>using namespace std;int n;int a[55][55];int anss[55];bool v[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 k=1;k<=n;k++){for(int i=1;i<=n;i++){if(anss[i]==0){int ji=0;for(int j=1;j<=n;j++){if(a[i][j]==k)ji++;}if(ji==n-1){anss[i]=k;break;}}}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(a[i][j]==k)a[i][j]=k+1;}}/*for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%d ",a[i][j]);printf("\n");}printf("\n");*/}for(int i=1;i<n;i++)printf("%d ",anss[i]);printf("%d\n",anss[n]);return 0;}
0 0
- CF618B - Guess the Permutation
- B. Guess the Permutation
- Guess the Permutation
- Codeforces 618B Guess the Permutation
- CodeForces 618B-Guess the Permutation【搜索】
- Wunder Fund Round 2016 B. Guess the Permutation
- CodeForces 618 B. Guess the Permutation(水~)
- CodeForces - 618B Guess the Permutation (模拟)
- Codeforces--618B--Guess the Permutation(规律)
- 【CodeForces 618B】Guess the Permutation(水题)
- 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(模拟)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation
- 1562 Guess the number
- Guess the Number
- ZOJ3333-Guess the Price
- 2016年主机游戏大作全方位预测
- SQLite的增删查改
- POJ 2253 - Frogger
- Android点击切换主题theme
- Unity3d 获取时间戳或获取北京时间
- CF618B - Guess the Permutation
- python 正则表达式
- POJ 1797 - Heavy Transportation
- java中最常用的类
- 【niubi-job——一个开源的分布式任务调度框架】-----安装教程
- Object-C--->Swift之(十)存储属性
- Dynamics CRM 2015/2016 Web API:新的数据查询方式
- java的8种基础数据类型
- POJ 3268 - Silver Cow Party