Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation 水题
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 水题的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
现在水平真的不够.只能够做做水题 A. Slime Combining 题意:就是给n个1给你.两个相同的数可以合并成一个数,比如说有两个相同的v,合并后的值就是v+1 思路:直接模拟栈 #inclu ...
- 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 ...
- 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 ...
- Codeforces Round #354 (Div. 2) A. Nicholas and Permutation 水题
A. Nicholas and Permutation 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nichol ...
- 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 ...
- 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 ...
随机推荐
- ORACLE TM锁
Oracle的TM锁类型 锁模式 锁描述 解释 SQL操作 0 none 1 NULL 空 Select 2 SS(Row-S) 行级共享锁,其他对象只能查询这些数据行 Select for upda ...
- html --- canvas --- javascript --- 在线画板
canvas功能十分强大,制作一个简易画板易如反掌,主要涉及canvas的画线能力,javascript鼠标点击事件 如有问题请参考:http://www.html5party.com/857.htm ...
- PermGen space Eclipse 终极解决方案
1.选中项目右键 run or debug configurations... 2.在 VM arguments 加入 -Xms128m -Xmx512m -XX:PermSize=64M -XX: ...
- JAVA分析html算法(JAVA网页蜘蛛算法)
近来有些朋友在做蜘蛛算法,或者在网页上面做深度的数据挖掘.但是遇到复杂而繁琐的html页面大家都望而却步.因为很难获取到相应的数据. 最古老的办法的是尝试用正则表达式,估计那么繁琐的东西得不偿失,浪费 ...
- Mapreduce执行过程分析(基于Hadoop2.4)——(二)
4.3 Map类 创建Map类和map函数,map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户需要覆写 ...
- 从数列1,2,3.......n 中 随意取几个数,使其和等于 m
//从数列1,2,3.......n 中 随意取几个数,使其和等于 m public static void Print(int n, int m, List<int> ...
- Apache Spark 架构
1.Driver:运行 Application 的 main() 函数并且创建 SparkContext. 2.Client:用户提交作业的客户端. 3.Worker:集群中任何可以运行 Applic ...
- Clean Code第三章<函数>
1.方法不要写太长,如果太长,抽取其中的逻辑到新的方法中 bad good 2.函数只做一件事 如果做了多件事,要在方法名里体现出来 3.每个函数一个抽象层级 4.函数名可以长一些,比长注释好 5.方 ...
- Java反射机制(取得类的结构)
通过反射得到一个类中的完整的结构,就要使用java.lang.reflect包中的以下几个类: Constructor:表示类中的构造方法 Field:表示类中的属性 Method:表示类中的方法 ...
- Win7 x64下进程保护与文件保护(ObRegisterCallbacks)
进程保护部分参考 http://bbs.pediy.com/showthread.php?t=168023 进程保护,在任务管理器不能结束进程 #ifndef CXX_PROTECTPROCESSX6 ...