散列-PAT.A1078 Hashing
来源:互联网 发布:21周胎儿发育标准数据 编辑:程序博客网 时间:2024/06/06 12:48
注意:本题考察点–二次探查法的上限为所给的用于求余的素数
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<string>#define maxSize 11111 //设置为10000就会出错using namespace std;int judgePrime(int ex) {//判断一个数是否为素数 int flag = 1; if (ex <= 1) return 0; for (int i = 2; i <= (int)sqrt(ex * 1.0); i++) { if (ex%i == 0) { flag = 0; break; } } return flag;}int main() { int n, Tsize; cin >> Tsize >> n; int test[maxSize]; int place[maxSize] = { 0 }; for (int i = 0; i < n; i++) { cin >> test[i]; } while (!judgePrime(Tsize)) Tsize++; //扩大到素数 for (int i = 0; i < n - 1; i++) { int temp = test[i] % Tsize; int k = 1; while (place[temp] && k < Tsize) { temp = (test[i] + k * k) % Tsize; k++; } //循环节为Tsize,二次探查法的上限 if (k >= Tsize) { cout << "- "; continue; } place[temp] = 1; cout << temp << " "; }//单独输出最后一个数的序号,保证格式 int temp = test[n-1] % Tsize; int k = 1; while (place[temp] && k < Tsize) { temp = (test[n-1] + k * k) % Tsize; k++; } if (k >= Tsize) { cout << "-" << endl; return 0; } place[temp] = 1; cout << temp; cout << endl; return 0;}
0 0
- 散列-PAT.A1078 Hashing
- pat-a1078. Hashing (25)
- PAT A1078.Hashing(25)
- PAT A1078 hashing (25)
- PAT A1078.Hashing
- PAT-A1078. Hashing (25)(哈希)
- PAT-A1078
- A1078. Hashing (25)
- PAT 09-散列3. Hashing - Hard Version (30)
- PAT 数据结构 09-散列1. Hashing (25)
- PAT a1078题解
- 散列 (Hashing)
- 散列(hashing)
- 散列2 Hashing
- PAT 数据结构 09-散列3. Hashing - Hard Version (30) 拓扑排序
- 11-散列2 Hashing
- 数据结构:散列(hashing)
- 11-散列4 Hashing
- 深入.NET平台 第四章 上机2 员工薪资
- Java中HashMap遍历的两种方式
- ubuntu常用命令
- Android界面布局
- jQuery-Ajax
- 散列-PAT.A1078 Hashing
- 工具类库系列(十)-Object
- Spark:Yarn-cluster和Yarn-client区别与联系
- Java枚举的七种常见用法
- linux中vim的配置
- Makefile通用版
- vertica数据库备份与恢复
- iOS10从app跳转到WiFi设置界面
- Callable和Runnable