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

  1. 2
  2. 1
  3. 124866
  4. 3
  5. 124866
  6. 111111
  7. 987651

Sample Output

  1. 1
  2. 8
  3.  
  4. 该题,整体思路有,不过会觉得肯定会超时,结果也超时了,后来搜了题解,有一个小小的技巧
    就是memset的时候,不整体memset,而是从0i+1,因为下一层循环对i取得膜,所以vis里面改变的下标都<=i!!!!!十分重要,不这样就会超时!!!
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. using namespace std;
  6. const int maxn=1e6+10;
  7. bool vis[maxn];
  8. int a[500];
  9. int main()
  10. {
  11. int t;
  12. scanf("%d",&t);
  13. while(t--)
  14. {
  15. int g;
  16. scanf("%d",&g);
  17. for(int i=0;i<g;i++) scanf("%d",&a[i]);
  18.  
  19. if(g==1) printf("1\n");
  20. else
  21. {
  22. int i;
  23. for(i=2;;i++)
  24. {
  25. memset(vis,0,sizeof(bool)*(i+1));//!!!!
  26. bool flag=0;
  27. for(int j=0;j<g;j++)
  28. {
  29. if(vis[a[j]%i]){flag=1;break;}
  30. else vis[a[j]%i]=1;
  31. }
  32. if(flag==0) break;
  33. }
  34. printf("%d\n",i);
  35. }
  36. }
  37. }

  

  1.  

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. sql cast,convert,QUOTENAME,exec 函数学习记录

    语法 使用 CAST: CAST ( expression AS data_type ) 使用 CONVERT: CONVERT (data_type[(length)], expression [, ...

  2. phpstorm配置Xdebug进行调试

    运行环境: PHPSTORM版本 : 8.0.1 PHP版本 : 5.6.2 xdebug版本:php_xdebug-2.2.5-5.6-vc11-x86_64.dll ps : php版本和xdeb ...

  3. 光盘作为yum源

    1.挂载光盘 mkdir /media/cdrom       //在/media下建立cdrom目录,默认情况是没有的  mount /dev/cdrom /mnt/cdrom2.进入 /etc/y ...

  4. Jmeter配置通过SSH连接的mysql数据库

    jmeter连接配置mysql数据库时,如果数据库服务器没有通过ssh连接,则只需要添加配置相应的jdbc参数就可以了.如果数据库服务器是通过SSH连接的,则需要通过中间远程连接工具来登录,此处使用的 ...

  5. OOP 面向对象的理解

    概念 面向对象编程(OOP)是一种编程语言模型,围绕对象是行为.数据.逻辑. 从历史上看,程序被视为一种逻辑程序,它接收输入数据,处理数据并生成输出数据. 基础 面向对象的3大核心思想:封装.继承.多 ...

  6. windows 安装 keras

    pip install keras 报错了,看报错信息是卡在scipy上了,查了一下 https://stackoverflow.com/questions/42240720/python-scipy ...

  7. Modbus通信协议 【 初识 Modbus】

    Modbus协议     Modbus 协议是应用于电子控制器上的一种通用语言.通过此协议,控制器相互之间.控制器经由网络(例如以太网)和其它设备之间可以通信.它已经成为一通用工业标准.有了它,不同厂 ...

  8. C++ enum的使用

    enum day {Sun,Mon,Tue,Wed,Thu,Fri,Sat};  默认情况下,枚举符的值从0开始,其后值总是前面一个+1.  即Sun=0,Mon=1,Tue=2,Wed=3,Thu= ...

  9. js keyup、keypress和keydown事件

    js keyup.keypress和keydown事件都是有关于键盘的事件 当一个按键被pressed 或released在每一个现代浏览器中,都可能有三种客户端事件. keydown event k ...

  10. Python基础二字符串和变量

    了解一下Python中的字符串和变量,和Java,c还是有点区别的,别的不多说,上今天学习的代码 Python中没有自增自减这一项,在转义字符那一块,\n,\r\n都是表示回车,但是对于不同的操作系统 ...