关闭

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

标签: numberspoj
204人阅读 评论(0) 收藏 举报
分类:

题目连接: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;
}
0
0
查看评论

POJ 2769 Reduced ID Numbers (同余定理)

/*应用同余定理模拟就好,让m从小到大递增注意验证是否满足条件即可。因为求的是同余所以bool数组可以比数据范围小10^(-1)倍。。。否则会超时。。。*/   Source Code Problem: 2769   User: imutzcy ...
  • imutzcy
  • imutzcy
  • 2013-02-22 00:56
  • 306

POJ 2769 Reduced ID Numbers (同余)

Reduced ID Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9153   Accepted: 3675 ...
  • u013068502
  • u013068502
  • 2015-04-21 21:00
  • 409

同余定理:poj2769 Reduced ID Numbers(标记数组)+hdu1021 Fibonacci Again(应用于递推公式)

Reduced ID Numbers Description T. Chur teaches various groups of students at university U. Every U-student has a unique Student Identification Numbe...
  • u012717411
  • u012717411
  • 2015-01-21 21:25
  • 733

2769 Reduced ID Numbers 同余问题

#include #include #include using namespace std; bool p[100001]; int d[100001]; int main() { int ncase; cin >> ncase; while (ncase...
  • u011503174
  • u011503174
  • 2013-07-25 20:23
  • 411

poj 2769 Reduced ID Numbers

Reduced ID Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8968   Accepted: 3604 ...
  • u014451076
  • u014451076
  • 2014-09-08 10:38
  • 281

Poj 2769 Reduced ID Numbers

Reduced ID Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8632   Accepted: 3461 ...
  • u011111528
  • u011111528
  • 2014-03-12 16:37
  • 330

poj 2769——Reduced ID Numbers

题意:给出一个数组,找出一个最小的整数使得数组中的所有元素模这个整数
  • u010734277
  • u010734277
  • 2014-06-21 02:02
  • 335

POJ 2769 Reduced ID Numbers

思路: 枚举 Reduced ID Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8847 Accepted: 3552 Description T. Chur teaches various gr...
  • Yuanchang_Best
  • Yuanchang_Best
  • 2014-08-21 14:44
  • 508

Reduced ID Numbers(POJ 2769)

题目:
  • npufz
  • npufz
  • 2014-08-22 15:37
  • 237

Reduced ID Numbers (同余)

题意:给出几个数 ,寻找一个最小数使这几个数mod它的值不相同 解析:暴力枚举从1开始,将模完的数保存在一个数组里,如果遇到相同的值,就增大值继续枚举。直到寻找到。 此处使用了mod[]数组,将模完的结果作为mod[]的下标,这样如果出现相同的值比较好发现(类比Find a multiple(鸽...
  • qq_32426313
  • qq_32426313
  • 2016-11-08 19:31
  • 161
    个人资料
    • 访问:131131次
    • 积分:4589
    • 等级:
    • 排名:第7641名
    • 原创:332篇
    • 转载:6篇
    • 译文:0篇
    • 评论:56条
    听歌啊
    最新评论