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

39 篇文章 0 订阅
26 篇文章 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值