二次探测法。表示第一次听说这东西。。。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std; const int maxn=;
bool flag[maxn];
long long m,n; bool prime(long long x)
{
if(x==) return ;
if(x==) return ;
for(long long i=;i*i<=x;i++)
if(x%i==) return ;
return ;
} int main()
{
memset(flag,,sizeof flag);
scanf("%lld%lld",&m,&n); while()
{
if(prime(m)) break;
m++;
} for(long long i=;i<=n;i++)
{
long long num; scanf("%lld",&num); int p=-;
for(long long j=;j<m;j++){ if(flag[(num+j*j)%m]==)
{
flag[(num+j*j)%m]=;
p=(num+j*j)%m; break;
}
}
if(p==-) printf("-");
else printf("%d",p); if(i<n) printf(" ");
else printf("\n");
}
return ;
}

PAT (Advanced Level) 1078. Hashing (25)的更多相关文章

  1. PAT (Advanced Level) 1070. Mooncake (25)

    简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...

  2. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...

  3. PAT (Advanced Level) 1010. Radix (25)

    撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...

  4. PAT (Advanced Level) 1003. Emergency (25)

    最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...

  5. PAT (Advanced level) 1003. Emergency (25) Dijkstra

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  6. PAT (Advanced Level) 1032. Sharing (25)

    简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...

  7. 【PAT甲级】1078 Hashing (25 分)(哈希表二次探测法)

    题意: 输入两个正整数M和N(M<=10000,N<=M)表示哈希表的最大长度和插入的元素个数.如果M不是一个素数,把它变成大于M的最小素数,接着输入N个元素,输出它们在哈希表中的位置(从 ...

  8. 1078. Hashing (25)【Hash + 探測】——PAT (Advanced Level) Practise

    题目信息 1078. Hashing (25) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The task of this problem is simple: in ...

  9. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

随机推荐

  1. JavaScript在智能手机上的应用-测试是否支持滑动事件

    ---------------------------- <script type="text/javascript">                        ...

  2. git基本命令--远程

    git clone: # clone到 <本地目录名> $ git clone <版本库的网址> <本地目录名> # 克隆版本库的时候,所使用的远程主机自动被Git ...

  3. 十三章:使用WEB字体

    1.WEB字体可以使用一系列文件类型,下面介绍三种字体类型: (1)内嵌OpenType (2)TrueType和OpenType台式机使用的标准字体文件类型 (3)WEB开放字体格式. 2.构造子集 ...

  4. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  5. UIImageView的UserInteractionEnabled什么时候为no

    UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件 特殊子类的覆盖 userInteractionEnabled属性默认值为YES,但UIView的一些子类中对 ...

  6. MJExtension的使用

    1. Plist → 模型数组 控制器中引用#import "MJExtension.h" 模型数组 = [模型类名 objectArrayWithFilename:@" ...

  7. 新手安装Oracle后的一些问题

      1.安装数据库服务端后,桌面上有个 打开之后点击一些按钮会叫你登录,用户名是SYSTEM,密码是安装的时候设置的密码(我设置的密码是root). . 2.在操作系统"运行"上输 ...

  8. LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义

    先简单的介绍下关于LVS负载均衡 LVS(Linux  Virtual Server)Linux服务器集群系统 针对高可伸缩,高可用服务的需求,给予IP层和内容请求分发的负载均衡调度解决方法,并在Li ...

  9. on-tap和on-click

    简单的说,当你点击移动设备屏幕上的一个点之后,on-tap会立刻触发,而on-click(可能)需要等待300ms才触发——这是移动设备浏览器为了检测是否存在双击的一个检测周期长度. 在移动设备上,应 ...

  10. mysql 连接两列

    以下划线符号,连接两列,作为查询结果: SELECT CONCAT(col_1,'_',col_2) FROM yourtable