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. Prism for WPF再探(基于Prism事件的模块间通信)

    上篇博文链接 Prism for WPF初探(构建简单的模块化开发框架) 一.简单介绍: 在上一篇博文中初步搭建了Prism框架的各个模块,但那只是搭建了一个空壳,里面的内容基本是空的,在这一篇我将实 ...

  2. jQuery实现表的编辑删除添加(增删改查)🌚

    代码 : (用到了bootstrap里面的全局css样式和组件,毕竟一把梭.

  3. VS代码生成工具ReSharper使用手册:配置快捷键(转)

    原文:http://blog.csdn.net/fhzh520/article/details/46364603 VS代码生成工具ReSharper提供了丰富的快捷键,可以极大地提高你的开发效率. 配 ...

  4. 使用performance monitor 查看 每一个cpu core的cpu time

    使用performance monitor 查看 每一个cpu core的cpu time: 打开performance monitor,添加 counter 如下 运行一段cpu bound 的代码 ...

  5. 【转】 CSS十问——好奇心+刨根问底=CSSer

    最近有时间,想把酝酿的几篇博客都写出来,今天前端小学生带着10个问题,跟大家分享一下学习CSS的一些体会,我觉得想学好CSS,必须保持一颗好奇心和刨根问底的劲头,而不是复制粘贴,得过且过.本人能力有限 ...

  6. [已解决]This dependency was not found: * common/stylus/index.styl in ./src/main.js To install it, you can run: npm install --save common/stylus/index.styl

    出现 This dependency was not found: * common/stylus/index.styl in ./src/main.js To install it, you can ...

  7. Android Studio 查看手机CPU信息

    在Android开发中,我们想要获取手机是什么CPU架构,可以通过下面方式: 1.进入adb 终端 adb shell 2.进入proc目录 cd /proc/ 3.查看cpu信息 cat cpuin ...

  8. PHP中域名绑定

    1.如果是集成环境,比如phpstudy则可以直接在工具中点击其他选项菜单->站点域名管理填好对应的域名和站点目录后点击新增,然后点击保存设置并生成配置文件,然后再打开hosts文件,增加对应的 ...

  9. Linux笔记---硬盘添加

    BZ创建了一个块云硬盘添加到了虚拟机里,然后按照平时挂在U盘的方式去挂载硬盘: mount  -t ext4 /dev/vdb  /mnt/xxxx 结果报出以下错误: mount: wrong fs ...

  10. Chris Richardson微服务翻译:微服务架构中的服务发现

    Chris Richardson 微服务系列翻译全7篇链接: 微服务介绍 构建微服务之使用API网关 构建微服务之微服务架构的进程通讯 微服务架构中的服务发现(本文) 微服务之事件驱动的数据管理 微服 ...