Description

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 = 106-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
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int t[310];
bool vis[1000010]; int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m,i,j;
scanf("%d",&m);
for(i=1;i<=m;i++)
cin>>t[i];
for(i=m;;i++)
{
memset(vis,false,i*sizeof(vis[0])); //时间172ms
for(j=1;j<=m;j++) //memset(vis,false,sizeof(vis)); tle
if(vis[t[j]%i]) break;
else vis[t[j]%i]=true;
if(j>m) break;
}
printf("%d\n",i);
}
return 0;
}


poj 2769 Reduced ID Numbers(memset使用技巧)的更多相关文章

  1. poj 2769 Reduced ID Numbers 同余定理

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

  2. C - Reduced ID Numbers 寒假训练

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

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

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

  4. poj 1651 http://poj.org/problem?id=1651

      http://poj.org/problem?id=1651Multiplication Puzzle   Time Limit: 1000MS   Memory Limit: 65536K To ...

  5. poj 1679 http://poj.org/problem?id=1679

    http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  6. POJ3278http://poj.org/problem?id=3278

    http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...

  7. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  8. POJ 2769

    http://poj.org/problem?id=2796 题意:求n个数的和乘以这n个数中的最小值的积最大的数,以及其范围. 思路:求每一个数两边的比其大的数的和,再乘以这个数.还有一个范围,用单 ...

  9. poj-3056 http://poj.org/problem?id=3056

    http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS   Memory Limit: 65536K Tot ...

随机推荐

  1. [转]java开发环境搭建

    分成两个部分: 1.下载安装jdk,并配置环境变量 链接:http://www.runoob.com/java/java-environment-setup.html 2.安装Eclipse 链接:h ...

  2. Primefaces的fileUpload组件使用

    最近在学习Primefaces(当然也是项目中需要用的).在使用其fileUpload遇到了不小的困难,现总结一下供大家及我自己今后参考使用. 1.首先是使用环境配置:正常的Primefaces开发环 ...

  3. Linux 二层协议架构组织

    本文主要讲解了Linux 二层协议架构组织,使用的内核的版本是2.6.32.27 为了方便理解,本文采用整体流程图加伪代码的方式从内核高层面上梳理了Linux 二层协议架构组织,希望可以对大家有所帮助 ...

  4. Swift - 获取屏幕点击坐标下所有对象(SpriteKit游戏开发)

    对于场景内对象元件的点击响应,我们可以在场景的touchesBegan()方法中内统一处理. SKScene中touchesBegan()是响应屏幕点击的方法,在这里面我们可以先获取点击位置下所有的对 ...

  5. 网页插入QQ 无需加好友

    <p>联系方式:1073351325<a href="tencent://message/?Menu=yes&uin=1073351325&Site=dsf ...

  6. C#判断文件是否正在被使用

    生成文件的时候,如果该文件夹下的同名文件被打开(或者被使用),如果这时再生成一个同名文件,则会提示文件正在被占用. 解决方法有两个,一个是保存的文件名改成该文件夹下不存在的(随机数之类的XXOO都行, ...

  7. 阿斯钢iojeg9uhw8uhy平

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  8. 积累的VC编程小技巧之滚动条

    1.设置滚动条的滚动大小 创建一个基于CScrollview的SDI Project(在第6步中选CScrollview) 若你已创建了,这步可以省略. 然后: 改为如 void CTestView: ...

  9. Android菜鸟的成长笔记(1)——Android开发环境搭建从入门到精通

    原文:Android菜鸟的成长笔记(1)--Android开发环境搭建从入门到精通 今天在博客中看到好多Android的初学者对Android的开发环境的搭建不熟悉而导致不能进行学习,所以我决定自己写 ...

  10. Java反射机制的使用方法

    Java的反射机制同意你在程序执行的过程中获取类定义的细节.有时候在程序执行的时候才得知要调用哪个方法,这时候反射机制就派上用场了. 获取类 类的获取方法有下面几种: forName().通过Clas ...