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)结构 简单理解:用最基本的向量(数组)作为底层物理存储结构,通过适当的散列函数在词条的关键码与向量单元的秩(下标)之间建立映射关系 ...
随机推荐
- ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...
- ASP里面令人震撼地自定义Debug类(VBScript)
不知道用ASP写代码的朋友是不是和我有一样的感受,ASP中最头疼的就是调试程序的时候不方便 我想可能很多朋友都会用这样的方法“response.write ”,然后输出相关的语句来看看是否正确.前几天 ...
- xml schema 中如何定义类似Map的结构
利用xs:unique关键字.在xs:element里添加unique节点,任意命名,然后用xs:selector来选择需要唯一的域, xs:field 里指定特定的字段. 例如:定义所有Item里的 ...
- ssh配置免登 Ubuntu环境
配置之前,可能需要修改下每台机器的hostname,修改方法 1.直接修改hostname文件:sudo vi /etc/hostname 2.重启服务器:shutdown -r now Ubuntu ...
- OpenStack安装后检查流程总结
安装后检查 1. 确保服务正常运行 首先查看服务的运行状态: #service xxx status 为防止对子服务有疏漏,可使用ps + grep 查看: # ps aux |grep xx 2. ...
- HttpApplication 对象的创建过程及HttpModule过滤器的内部实现过程
最近通过Reflector学习了一下asp.net内部的原理,做做笔记,方便以后查阅. 先看下HttpApplication 对象的创建过程 从IHttpHandler applicationInst ...
- ObjectInputStream缓存数据
DataManager /** * 本地数据的存储 * @author Administrator * */ public class DataManager { private static fin ...
- JDBC编程之数据准备
--------------------siwuxie095 JDBC 编程之数据准备 启动 MySQL 服务,在管理员模式下的 CMD 窗口中输入 net start mysqldb 「对应的关闭 ...
- Impala介绍
Impala介绍 Impala支持的文件格式 Impala可以对Hadoop中大多数格式的文件进行查询.它能通过create table和insert的方式将一部分格式的数据加载到table中,但值得 ...