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. xcode-build/version-bump

    # xcode-build-bump.sh # @desc Auto-increment the build number every time the project is run. # @usag ...

  2. Android KeyCode(官方)

    Constants public static final int ACTION_DOWN Added in API level 1 getAction() value: the key has be ...

  3. 如何将内存中的位图数据绘制在DC上

    假如你定义了一个位图类,里面包含位图头,位图信息头,调色板,位图数据.然后你按照位图的格式将位图文件读入你的类中,现在你知道了位图的全部信息了.主要信息包含在位图信息头里面,数据则在位图数据缓冲里面. ...

  4. axure网格设置

    Axure默认的界面是没有吧网格显示出来,没有网格在制作原型的时候,对齐方面不是很好,个人习惯还是把网格显示出来,便于组件对齐和布局. 其实本来这篇文章应该叫做网格与参考线,只是本人对参考线的应用还很 ...

  5. Basic4android:多功能的Android应用软件快速开发平台

    Basic4android 是目前最简单.最强大的Android平台快速应用开发工具. ( "Basic4android is the simplest and most powerful ...

  6. ftk学习记(对话框篇)

    [声明:版权全部,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 前面谈到了输入法,首先看一看效果. 上面有4个输入框,大家能够分别试试,看看效果怎样. 今天,我 ...

  7. oradebug推进scn

    有时候我们遇到例如以下错误: ORA-01092: ORACLE instance terminated. Disconnection forced ORA-00600: internal error ...

  8. Mac Python路径总结

    Mac 下Python 可以多版本的并存,并且Python的目录也有好几个,不过总体来说,Mac 自带的有python 还是比较方便的 Mac 系统自带的又Python ,可能Python版本需要更新 ...

  9. Could not find or load main class

    Then add '.' to your $CLASSPATH with CLASSPATH=.:$CLASSPATH or as a paramater with java -classpath . ...

  10. oracle在desc表时,name 和type列不能格式化问题(占位过长)

    今天玩Oracle的时候,遇到一个让人很无语的问题,我desc表的时候,总是发现name列和type 列占位太多, 无法很直观明白的显示出来各个列值,就像下面的样子: 这样让人很不舒服,当然,一看到列 ...