一、热身 [Cloned] P - Reduced ID Numbers

原题:

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 = 10 6-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.

题解:

同余定理的应用,给出一组n个数据,找出一个数m使得每一个数对m求余都不相同。思路就是从1开始枚举i,直到找到一个i使得集合中的任意两个数对i的余数都不相同。设置一个bool型的数组p来判断是否有相同的余数。

代码:AC

#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
 
const int maxn= 500;
 
int main()
{
    bool p[100010];
    int arr[maxn];
    int T;
    cin>>T;
    while(T--)
    {
        int n,i,j;
        cin>>n;
        for( i = 0; i < n; ++i)
            cin>>arr[i];
        for( i = 1; ; ++i)
        {
            bool flag = true;
            memset(p, false, sizeof(p));
            for(j = 0; j < n; ++j)
            {
                if(p[ arr[j]%i ])
                {
                    flag = false;
                    break;
                }
                p[ arr[j]%i ] = true;
            }
            if(flag)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值