POJ 2769 Reduced ID Numbers [同余]【数论】

原创 2016年09月12日 00:25:33

题目连接:http://poj.org/problem?id=2769
——————————-.
Reduced ID Numbers
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9927 Accepted: 3960
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
Source

Northwestern Europe 2005

————————————–.
题目大意:
就是给你N个数(ni<1e6) 找一个数使得这N个数都不同于这个数 输出最小的这个数

解题思路:
开始一顿推公式 推啊推 然后发现根本推不出来 ;
然后看了一下数据范围 发现N*1e6 时间给的就是2S 暴力就行了啊

然后就这样水过去了。。。。

从1开始枚举就行了 然后判断下所有数对其求余的值 然后hash记录一下 就能判断行不行了 行了就直接输出 不行就接着枚举 因为数值最大只有1e6 所以最后肯定有一个数能满足题意。。。。

最讨厌做这种暴力题目了 说难真不难 但是我这种ZZ根本不想搞暴力 结果就各种GG
其实还是思维定式太重了 想问题 越来越极限。。。

附本题代码
—————————————–。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

/*********************INPUT*************************/
#define s2l(a,b)   scanf("%d%d",&a,&b)
#define s2_l(a,b)  scanf("%I64d%I64d",&a,&b)

/*********************OUTPUT*************************/
#define pr1l(a)    printf("%d",a);
#define pr1_l(a)   printf("%I64d",a);
#define pr1ll(a)   printf("%lld",a);
#define space      printf(" ");
#define line       printf("\n");

/****************************************/
#define _LL __int64
/****************************************/
#define fr(a,b,c)  for(int a=b;a<c;a++)
#define mem(a,b,c) for(int i=0;i<=c;i++)a[i]=b;
typedef long long int LL ;
#define INF 0x3f3f3f3f
#define pb push_back

#define lalal puts("*******");
/*************************************/

const int MOD = 1e9+7;
const int M = 1e5+10;

int a[M] , b[M];
int n;

bool check(int m)
{
    memset(b , 0 , sizeof(b));
    for(int i = 0 ; i < n ; i ++)
    {
        if(b[a[i] % m])
            return false;
        else
            b[a[i] % m] = 1;
    }
    return true;
}

int main()
{

    int _;
    while(scanf("%d",&_)!=EOF)
        while(_--)
        {
            scanf("%d",&n);
            for(int i = 0 ; i < n ; i ++)
                scanf("%d",&a[i]);

            for(int m = 1 ; m < M ; m ++)
            {
                if(check(m))
                {
                    printf("%d\n",m);
                    break;
                }
            }
        }
    return 0;
}
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。

相关文章推荐

POJ 2769 Reduced ID Numbers 同余定理

Reduced ID Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8989 ...

[POJ2769] Reduced ID Numbers

题目描述T.Chur在大学里教授不同群体的学生,每个学生都有一个独特的学生证号码(SIN),是0~10^6范围内的整数。但T.Chur觉得SIN的范围太大以至于不便于确定每个学生,故希望在每个组里都能...

解题报告 之 POJ2769 Reduced ID Numbers

POJ2769 ,Reduced ID Numbers,数论,同余,ACM T. Chur teaches various groups of students at university U. E...
  • maxichu
  • maxichu
  • 2015年05月11日 12:18
  • 560

Reduced ID Numbers(POJ 2769)

题目:
  • npufz
  • npufz
  • 2014年08月22日 15:37
  • 215

Poj 2769 Reduced ID Number

Reduced ID Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7882...

POJ2769同余问题

题目地址:http://poj.org/problem?id=2769DescriptionT. Chur teaches various groups of students at universi...

TOJ 2353.Reduced ID Numbers

题目链接:http://acm.tju.edu.cn/toj/showp2353.html 2353.   Reduced ID Numbers Time Limit: 1...

POJ 2635 The Embarrassed Cryptographer [高精度求余+同余模定理]【数论】

ACMer与Coder的交流分享地POJ2635-The Embarrassed Cryptographer转载请注明出处:優YoU http://user.qzone.qq.com/2890654...

[数论] 同余方程组 poj2891 Strange Way to Express Integers

poj2891 Strange Way to Express Integers P=b1(mod a1); P =b2(mod a2); P =b3(mod a3); …… P =bn(...

20140714 「初等数论 - 拓展欧几里得+同余模方程」POJ 1061 青蛙的约会

Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statist...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2769 Reduced ID Numbers [同余]【数论】
举报原因:
原因补充:

(最多只允许输入30个字)