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 ...
随机推荐
- matlab 调用VLfeat库开篇问题
准备工作见此网站 :http://cnyubin.com/?p=85 保存关闭startup.m文件后 重新打开matlab后 在命令行输入path或者vl_version无法检测到库已安装到matl ...
- 解决Socket.IO在IE8下触发disconnect时间过长
本文地址: http://www.cnblogs.com/blackmanba/p/solve-socketIO-IE8-emit-disconnect-too-long.html或者http://f ...
- Page Scroll Menu (页面中锚点菜单)
Technorati 标签: Page Scroll Menu,页面锚点菜单,Menu,Too Long,页面太长 当页面太长时,会导致浏览不便,这时就需要一个页面锚点菜单(Page Scroll ...
- DNN 错误代码 0x80070005 解决方案
在IIS上创建DNN站点,可能出现的错误代码:0x80070005,因为权限不足而不能访问DNN. 解决方法:打开IIS, 1.右键目标网站->编辑权限->安全->添加组或者用户 “ ...
- struts2传递List对象(复合对象)
1.前台jsp界面: <%@ page language="java" contentType="text/html; charset=utf-8" pa ...
- erlang 时间处理
常用代码 date()返回P{年,月,日} erlang:now转本地时间 > calendar:now_to_local_time(erlang:now()). {{,,},{,,}} erl ...
- ubuntu下apt-get update出现hash校验和错误
可能原因 校园网进行网络缓存导致内容滞后. 解决办法 先清除旧的apt-get更新列表 sudo rm -rf /var/lib/apt/lists/* 使用代理服务器或者VPN 重新更新 sudo ...
- Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)
Count the Trees Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...
- 解决SQL Server Always 日志增大的问题-摘自网络
配置了Alwayson之后,因为没有只能使用完全恢复模式,不能使用简单或大容量日志模式,所以日志不断增长,不能使用改变恢复模式的方式清空日志 手动操作收缩或截断日志也无效 读了一些文章后发现,有人使用 ...
- dom 冒泡事件
<!doctype html> <html> <head> <meta charset="utf-8"> <style> ...