Given a hash table of size N, we can define a hash function (. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequence of input numbers.

However, now you are asked to solve the reversed problem: reconstruct the input sequence from the given status of the hash table. Whenever there are multiple choices, the smallest number is always taken.

Input Specification:

Each input file contains one test case. For each test case, the first line contains a positive integer N (≤), which is the size of the hash table. The next line contains N integers, separated by a space. A negative integer represents an empty cell in the hash table. It is guaranteed that all the non-negative integers are distinct in the table.

Output Specification:

For each test case, print a line that contains the input sequence, with the numbers separated by a space. Notice that there must be no extra space at the end of each line.

Sample Input:

11
33 1 13 12 34 38 27 22 32 -1 21

Sample Output:

1 13 12 21 33 34 38 27 22 32
//参考
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int N = ;
int num[N], indegree[N];
struct cmp {
bool operator()(int i, int j) {
return num[i] > num[j];
}
};
int main() {
int i, j, n, m, k, flag = ;
scanf("%d", &n);
vector<vector<int> > g(n);
priority_queue<int, vector<int>, cmp> q;
for (i = ; i < n; i++)
scanf("%d", &num[i]); for (i = ; i < n; i++) {
if (num[i] > ) {
k = num[i] % n;
indegree[i] = (i + n - k) % n;
if (indegree[i]) {
for (j = ; j <= indegree[i]; j++)
g[(k + j) % n].push_back(i);
}
else q.push(i);
}
} while (!q.empty()) {
i = q.top();
q.pop();
if (!flag) {
flag = ;
printf("%d", num[i]);
}
else printf(" %d", num[i]);
for (j = ; j < g[i].size(); j++) {
if (--indegree[g[i][j]] == )
q.push(g[i][j]);
}
}
return ; }

11-散列4 Hashing - Hard Version (30 分)的更多相关文章

  1. 11-散列4 Hashing - Hard Version (30 分)

    Given a hash table of size N, we can define a hash function H(x)=x%N. Suppose that the linear probin ...

  2. pat09-散列3. Hashing - Hard Version (30)

    09-散列3. Hashing - Hard Version (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HE, Qin ...

  3. PTA 11-散列4 Hard Version (30分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/680 5-18 Hashing - Hard Version   (30分) Given ...

  4. PTA 07-图5 Saving James Bond - Hard Version (30分)

    07-图5 Saving James Bond - Hard Version   (30分) This time let us consider the situation in the movie ...

  5. JavaScript数据结构-11.散列

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 11-散列4 Hashing - Hard Version

    题目 Sample Input: 11 33 1 13 12 34 38 27 22 32 -1 21 Sample Output: 1 13 12 21 33 34 38 27 22 32 基本思路 ...

  7. 纯数据结构Java实现(11/11)(散列)

    欢迎访问我的自建博客: CH-YK Blog.

  8. 07-图5 Saving James Bond - Hard Version (30 分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  9. 散列(Hash)表入门

    一.概述 以 Key-Value 的形式进行数据存取的映射(map)结构 简单理解:用最基本的向量(数组)作为底层物理存储结构,通过适当的散列函数在词条的关键码与向量单元的秩(下标)之间建立映射关系 ...

随机推荐

  1. 判断iOS系统的Model

    获取iOS系统的Model   (参考网址:https://www.theiphonewiki.com/wiki/Models) + (NSString *)getModel{ struct utsn ...

  2. BZOJ4010:[HNOI2015]菜肴制作

    我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...

  3. 洛谷【P1601】A+B Problem(高精)

    题目传送门:https://www.luogu.org/problemnew/show/P1601 高精度加法板子.我们灵性地回忆一波小学学加法列竖式的场景(从\(6\)岁开始口算从未打过草稿的大佬请 ...

  4. centos6.5安装zookeeper教程(三)

    阅读前建议先阅读: http://www.cnblogs.com/duenboa/articles/6665159.html   1. 下载安装文件zookeeper-3.4.6.tar.gz 镜像地 ...

  5. Sequence Models 笔记(二)

    2 Natural Language Processing & Word Embeddings 2.1 Word Representation(单词表达) vocabulary,每个单词可以使 ...

  6. 【机器学习】关联规则挖掘(二):频繁模式树FP-growth

    Apriori算法的一个主要瓶颈在于,为了获得较长的频繁模式,需要生成大量的候选短频繁模式.FP-Growth算法是针对这个瓶颈提出来的全新的一种算法模式.目前,在数据挖掘领域,Apriori和FP- ...

  7. CSS学习系列2 -- CSS中的清除浮动

    CSS中有一个很常见的问题,就是元素的浮动. 那么,到底什么是元素的浮动呢,我们来看一个例子 举个例子,在一个div里面内部有浮动元素的话,这个浮动元素会让这个div的高度塌陷. .myDiv{ ba ...

  8. 9.利用msfvenom生成木马

    这篇文章来介绍一下msf中一个生成木马的msfvenom模块. msfvenom命令行选项如下: 英文原版: 中文版: Options: -p, --payload <payload> 指 ...

  9. 20169201 2016-2017-2 实验二《Java面向对象程序设计》

    实验一:程序设计中临时变量的使用 代码托管 1.删除数组中的元素5 for(int i = 4; i < arr.length - 1; i ++){ arr[i] = arr[i + 1]; ...

  10. oracle开发so easy(一)

    如何让你的程序可以在oracle数据库和sqlserver数据库自由切换? 如何让你从跨数据库开发的不适中解脱出来? 跟我来吧,我们一起开始entity framework的开发之旅.是的,entit ...