11-散列4 Hashing - Hard Version (30 分)
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 分)的更多相关文章
- 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 ...
- pat09-散列3. Hashing - Hard Version (30)
09-散列3. Hashing - Hard Version (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HE, Qin ...
- PTA 11-散列4 Hard Version (30分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/680 5-18 Hashing - Hard Version (30分) Given ...
- 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 ...
- JavaScript数据结构-11.散列
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 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 基本思路 ...
- 纯数据结构Java实现(11/11)(散列)
欢迎访问我的自建博客: CH-YK Blog.
- 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 ...
- 散列(Hash)表入门
一.概述 以 Key-Value 的形式进行数据存取的映射(map)结构 简单理解:用最基本的向量(数组)作为底层物理存储结构,通过适当的散列函数在词条的关键码与向量单元的秩(下标)之间建立映射关系 ...
随机推荐
- msdtc中rpc调试
http://www.cnblogs.com/nzperfect/archive/2011/11/03/2234595.html 1 工具: dtcping 2 配置 3 netboise
- bzoj 3926: 诸神眷顾的幻想乡 广义后缀自动机
题目: Description 幽香是全幻想乡里最受人欢迎的萌妹子,这天,是幽香的2600岁生日,无数幽香的粉丝到了幽香家门前的太阳花田上来为幽香庆祝生日. 粉丝们非常热情,自发组织表演了一系列节目给 ...
- socket发送结构体
struct send_info {char info_from[20]; //发送者IDchar info_to[20]; //接收者IDint info_length; //发送的消息主体的长度c ...
- virtual judge(专题一 简单搜索 A)
问题描述: Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘, ...
- js右击事件
先贴代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- 一 Optional
从Java8 引入的一个很有趣的特性是Optional类.Optional类主要解决的问题是臭名昭著的空指针异常(NullPointerException). 一: 创建Optional对象: ...
- js---数组习题---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Ubuntu 切换root用户是时出现su Authentication failure
su root 时出现错误su Authentication failure 原因是没有给root用户设置密码 sudo passwd root
- mysql 简单的sql优化示例[不定时更新]
对于慢sql的分析步骤: 1) desc|explain sql 查看执行计划, 对于type很慢的, 分析是否建立了对应字段的索引 2) 进行排除法, 把子查询抽离出来, 单独执行,定位慢查询是哪个 ...
- [51nod1384]全排列
法一:next_permutation函数,两个参数分别为起始指针和末尾指针. #include<bits/stdc++.h> using namespace std; typedef l ...