Reduced ID Numbers
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9310   Accepted: 3740

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
/*poj2769
*题意:给出g个数,求出最小的数使得这g个数模上这最小的数的余数是唯一的
*算法分析:看题目限制时间为2s,第一想法就是扫描了,从1开始到最大的数加1进行扫描,
*判断余数是否唯一。是则结束 ,这里注意地方就是不能刚好到最大的数结束、而是到最大的数加1
*结束,我试了下刚好扫到最大的数WA了、、、、
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std; int a[310];
int b[310]; //保存余数 int main() {
int t;
cin >> t;
while (t --) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int n;
cin >> n;
for (int i = 0; i<n; i++)
cin >> a[i];
sort(a, a+n);
int p = a[n-1];
int flag = 1, res, flag1 = 1;
for (int i = 1; i<=p+1 && flag1; i++) {
flag = 1;
for (int j = 0; j<n; j++) {
b[j] = a[j] % i;
}
sort(b, b+n);
for (int j = 0; j<n-1 && flag; j++) {
if (b[j] == b[j+1]) {
flag = 0;
}
}
if (flag) {
res = i;
flag1 = 0;
}
memset(b, 0, sizeof(b));
}
//cout << flag<< endl;
//cout << b[0]<< endl<< b[1]<< endl<< b[2]<< endl;
cout << res << endl;
} return 0;
}

不怕脚下的路有多难走、就怕你压根不想走下去、、

POJ_2769同余问题的更多相关文章

  1. float 对整形的取余运算

    取余是针对整形的,但是有时候一些特殊需求,我们需要 float 型对整形取下余数.比如,将角度化到 0- 360 范围内. 今天看到 lua 的实现方式: a % b == a - math.floo ...

  2. JS利用取余实现toggle多函数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. salesforce 零基础学习(四十三)运算取余

    工作中遇到一个简单的小问题,判断两个数是否整除,如果不整除,获取相关的余数. 习惯java的我毫不犹豫的写下了代码 public Boolean isDivisibility(Integer divi ...

  4. poj1006Biorhythms(同余定理)

    转自:http://blog.csdn.net/dongfengkuayue/article/details/6461298 本文转自head for better博客,版权归其所有,代码系本人自己编 ...

  5. PHP大数(浮点数)取余

    一般我们进行取余运算第一个想到的就是用百分号%,但当除数是个很大的数值,超出了int范围时,这样取余就不准确了. php大数(浮点数)取余函数 /** * php大数取余 * * @param int ...

  6. NOIP2014 uoj20解方程 数论(同余)

    又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...

  7. JAVA中取余(%)规则和介绍

    在java中%的含义为取余. java :a%b 数学公式a%b=a-(a/b)*b

  8. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  9. C语言fmod()函数:对浮点数取模(求余)

    头文件:#include <math.h> fmod() 用来对浮点数进行取模(求余),其原型为:    double fmod (double x); 设返回值为 ret,那么 x = ...

随机推荐

  1. .NET开发一个微信跳一跳辅助程序

    昨天微信更新了,出现了一个小游戏"跳一跳",玩了一下 赶紧还蛮有意思的 但纯粹是拼手感的,玩了好久,终于搞了个135分拿了个第一名,没想到过一会就被朋友刷下去了,最高的也就200来 ...

  2. table常用的属性以及用法

    <table><table/>先定义一个表格这个就没得讲了,<caption>表示这个表格的标题 <table border="6"> ...

  3. SP的封装(数据持久化方式一)

    1.先看一段描述: Interface for accessing and modifying preference data returned by Context.getSharedPrefere ...

  4. MySQL in or效率对比

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/60 考虑如下两个sql: select * from table ...

  5. 二分查找(折半查找)C++

    二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好,占用系统内存较少: 其缺点是要求待查表为有序表,且插入删除困难. 因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 首先,假设表 ...

  6. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解 ----转载

    1.(function($) {-})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){-} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...

  7. js、jQuery、layer实现弹出层的打开、关闭

    打开layer layer.open({ type: 2, title: '新增收货地址', shadeClose: true,//点击阴影关闭 shade: 0.8, area: ['900px', ...

  8. 最短的IE判断var ie=!-[1,]分析

    以前最短的IE判定借助于IE不支持垂直制表符的特性搞出来的. 复制代码代码如下:  var ie = !+"\v1";  仅仅需要7bytes!参见这篇文章,<32 byte ...

  9. C# System.Windows.Forms.NumericUpDown 控件全选其中文字

    num_length.Focus();                    UpDownBase updbText = (UpDownBase)num_length;                 ...

  10. vue 全局插槽 全局插座

    场景: slot 能够让父组件内容插入到子组件中,但是子孙组件不能够使用slot直接插入内容.在弹窗的时候,全屏弹窗需要直接在组件最上层显示,如果父组件级别不够,弹出就可能不是全屏的. 知识点: 1: ...