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. Linux给命令设置别名

    查看命令别名:alias alias 设置命令别名:alias 别名='命令' alias ll='ls -l' 取消命令别名:unalias 别名 unalias ll 命令永久生效 上面直接在sh ...

  2. JavaWeb学习 (十四)————JSP基础语法

    一.JSP模版元素 JSP页面中的HTML内容称之为JSP模版元素.  JSP模版元素定义了网页的基本骨架,即定义了页面的结构和外观. 二.JSP表达式 JSP脚本表达式(expression)用于将 ...

  3. HAPRoxy(一):HAProxy基本配置、调度算法与tcp、http、heath模式配置示例

    一.HAProxy安装 1.HAProxy简单介绍 HAProxy虽然名字前有HA,但它并不是一款高可用软件,而是一款用于实现负载均衡的软件,可实现四层与七层的负载均衡. 2.yum安装HAProxy ...

  4. mui 实用封装销毁页面

    /* * 描述:页面销毁封装 * 说明:针对订单特殊定位页面 * 返回首页,页面空白前进行销毁页面处理 * 使用:plusReady之后 */ (function(w) { var destructi ...

  5. Java 基础系列合集

    Java基础知识你知道多少? Java特性 Java三大特性:封装,继承,多态 Java 抽象类与接口 Java 浅拷贝和深拷贝 Java static和final Java 内部类.静态内部类.匿名 ...

  6. 对Spring中IOC和DI的理解

    前几篇讲了Spring中IOC和DI的用法,本篇应该放到三篇之前,但一直没有想到好的讲解方式,后参考https://blog.csdn.net/luoyepiaoxue2014/article/det ...

  7. InheritParasitic.js

    // 寄生式继承 // 其基本思路是类似创建对象时的工厂模式,将继承过程封装在一个函数里,然后返回一个对象 function createObject(o){ var clone = Object.c ...

  8. javascript刷新父页面的各种方法汇总

    1.用iframe.弹出子页面刷新父页面iframe <script language=JavaScript> parent.location.reload(); </script& ...

  9. loadrunner 运行脚本-Run-time Settings->General->Additional attributes设置

    运行脚本-Run-time Settings->General->Additional attributes设置 by:授客 QQ:1033553122 作用说明 为Vuser脚本提供额外 ...

  10. ionic打包报错Execution failed for task ':processDebugResources'

    ionic 打包的时候报了这样一个错误:Execution failed for task ':processDebugResources' 分析: compile "com.android ...