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. Boost Coroutine2 - stackful coroutine简介

    协程可以很轻量的在子例程中进行切换,它由程序员进行子例程的调度(即切换)而不像线程那样需要内核参与,同时也省去了内核线程切换的开销,因为一个协程切换保留的就是函数调用栈和当前指令的寄存器,而线程切换需 ...

  2. [数据结构]C语言栈的实现

    有始有终,所以我准备把各种数据结构都讲一次,栈也分顺序存储和链式储存,这里我们选择链式存储来讲,顺序存储没有难度(链式其实也是) 作为数据结构中最简单的栈,这里不会说太多,首先考虑一下下面的model ...

  3. 【Zookeeper】源码分析之服务器(三)之LeaderZooKeeperServer

    一.前言 前面分析了ZooKeeperServer源码,由于QuorumZooKeeperServer的源码相对简单,于是直接分析LeaderZooKeeperServer. 二.LeaderZooK ...

  4. Wincc的使用

    1.组态项目步骤 1)启动Wincc 2)建立项目 3)选择及安装通信驱动程序 4)定义变量 5)建立和编辑过程画面 6)指定Wincc运行系统的属性 7)激活Wincc画面 8)使用变量模拟器测试过 ...

  5. Ryz的鬼题

    蚂蚁(ant)[题目描述]  小 R 种了一棵苹果树,这棵树上有 n 个节点(标号从 0 到 n-1),有 n-1 条树枝连接这  n 个节点,这 n 个节点相互连通.每条树枝的长度为 1.  苹果树 ...

  6. bzoj 1566: [NOI2009]管道取珠

    Description   Input 第一行包含两个整数n, m,分别表示上下两个管道中球的数目. 第二行为一个AB字符串,长度为n,表示上管道中从左到右球的类型.其中A表示浅色球,B表示深色球. ...

  7. ffmpeg常用命令---转

    1.分离视频音频流 ffmpeg -i input_file -vcodec copy -an output_file_video //分离视频流 ffmpeg -i input_file -acod ...

  8. windows 命令行打开浏览器

    在命令行打开百度 start chrome www.baidu.com

  9. Git知识总览(一) 从 git clone 和 git status 谈起

    本篇博客是整理git相关知识的第一篇,因为之前一直是用SourceTree对Git的命令行操作用的不是特别熟,于是乎过了一遍ProGit(链接:https://git-scm.com/book/zh/ ...

  10. Git 进阶 —— 远程仓库

    一.远程仓库怎么玩 1. 自己搭建一个运行Git的服务器 Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上,但肯定有一台机器有着最原始的版本库,然后别的机器来克隆这个原始版本库,这 ...