T. Chur teaches various groups of students at university U. Every U-student has a unique Student Identification Number (SIN). A SIN s is an integer in the range 0 ≤ s ≤ MaxSIN with MaxSIN = 10 6-1. T. Chur finds this range of SINs too large for identification within her groups. For each group, she wants to find the smallest positive integer m, such that within the group all SINs reduced modulo m are unique.

Input

On the first line of the input is a single positive integer N, telling the number of test cases (groups) to follow. Each case starts with one line containing the integer G (1 ≤ G ≤ 300): the number of students in the group. The following G lines each contain one SIN. The SINs within a group are distinct, though not necessarily sorted.

Output

For each test case, output one line containing the smallest modulus m, such that all SINs reduced modulo m are distinct.

Sample Input

2
1
124866
3
124866
111111
987651

Sample Output

1
8 该题,整体思路有,不过会觉得肯定会超时,结果也超时了,后来搜了题解,有一个小小的技巧
就是memset的时候,不整体memset,而是从0到i+1,因为下一层循环对i取得膜,所以vis里面改变的下标都<=i!!!!!十分重要,不这样就会超时!!!
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int maxn=1e6+10;
bool vis[maxn];
int a[500];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int g;
scanf("%d",&g);
for(int i=0;i<g;i++) scanf("%d",&a[i]); if(g==1) printf("1\n");
else
{
int i;
for(i=2;;i++)
{
memset(vis,0,sizeof(bool)*(i+1));//!!!!
bool flag=0;
for(int j=0;j<g;j++)
{
if(vis[a[j]%i]){flag=1;break;}
else vis[a[j]%i]=1;
}
if(flag==0) break;
}
printf("%d\n",i);
}
}
}

  

												

C - Reduced ID Numbers 寒假训练的更多相关文章

  1. G - Reduced ID Numbers(第二季水)

    Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...

  2. poj 2769 Reduced ID Numbers(memset使用技巧)

    Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...

  3. poj 2769 Reduced ID Numbers 同余定理

    链接:http://poj.org/problem?id=2769 题意:寻找数m,是的对于n个数的余数不同 思路:暴力,优化:同余部分不用测试 代码: #include <iostream&g ...

  4. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  5. 寒假训练——搜索——C - Robot

    The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...

  6. 寒假训练——搜索 G - Xor-Paths

    There is a rectangular grid of size n×mn×m . Each cell has a number written on it; the number on the ...

  7. 寒假训练——搜索 E - Bloxorz I

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

  8. 寒假训练 A - A Knight's Journey 搜索

    Background The knight is getting bored of seeing the same black and white squares again and again an ...

  9. FZU ICPC 2020 寒假训练 4 —— 模拟(一)

    P1042 乒乓球 题目背景 国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中11分制改革引起了很大的争议,有一部分球员因为无法适应新规则只能选择退役.华华 ...

随机推荐

  1. Go语言学习笔记(二) [变量、类型、关键字]

    日期:2014年7月19日 1.Go 在语法上有着类 C 的感觉.如果你希望将两个(或更多)语句放在一行书写,它们 必须用分号分隔.一般情况下,你不需要分号.   2.Go 同其他语言不同的地方在于变 ...

  2. [SCOI2012] 喵星球上的点名

    Description 给定 \(N\) 个姓名串和 \(M\) 个点名串.询问每个点名串点到了多少姓名和每个姓名串被点到了几次.\(N\leq 5\cdot 10^4,M\leq 10^5\). S ...

  3. js串口通信 调用MSCOMM32控件 链接电子秤(完整版实现方案)

    硬件环境:RS232转USB串口线*1 电子秤*1(本人采用G&G E600Y-C型号称重仪) 电子秤原装RS232数据线*1 计算机*1 软件环境:RS232转USB串口线驱动(这个可以在串 ...

  4. 【esayui】扩展验证方法,控件验证

    基础验证 //页面调用方法$.extend($.fn.validatebox.defaults.rules, { 验证电话 IsPhoneRex: {validator: function (valu ...

  5. 【Servlet】1、Servlet监听器及相关接口

    Servlet监听器用于监听一些重要事件的发生,监听器对象可以在事情发生前.发生后可以做一些必要的处理. 接口: 目前Servlet2.4和JSP2.0总共有8个监听器接口和6个Event类,其中Ht ...

  6. java数据写入Excel

    正好最近公司要写一个对账的功能,后台用java从银行获得对账信息,数据是json类型的,然后写入excel中发送给一卡通中心的服务器上,网上找了很多代码,然后整合和改正,代码如下. import ja ...

  7. vue常用笔记

    vue源码解析(勾三股四):http://jiongks.name/blog/vue-code-review/ 0.npm: https://www.npmjs.com/ 1. package.jso ...

  8. HappenBefore

    计算机芯片在操作指令的步骤: 1.获取指令 2.指令进行解码 3.去寄存器里取值 4.开始计算结果(操作) 5.将结果写会到寄存器中 执行代码的顺序可能与编写代码不一致,及虚拟机优化代码顺序,则为指令 ...

  9. npm 走 privoxy 代理经常出现 shasum check failed 的解决办法

    今天在下载一个比较大的项目,经常 shasum check failed ,太烦了,于是想切淘宝源,分别尝试 nrm 切换和传递 --registry ,结果都出现 Unexpected end of ...

  10. 【读书笔记】iOS-手势识别

    一,事件处理机制 事件是当用户手指触及屏幕,或地屏幕上滑动,或摇晃设备等时候,系统不断地把这些事件通过消息发送给应用程序对象.在iOS设备中能够捕获的事件有3种:触摸事件,移动事件和多媒体远程控制事件 ...