zoukankan      html  css  js  c++  java
  • POJ_2769同余问题

    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;
    }

    不怕脚下的路有多难走、就怕你压根不想走下去、、
  • 相关阅读:
    【26.09%】【codeforces 579C】A Problem about Polyline
    【水水水】【洛谷 U4566】赛车比赛
    【24.58%】【BZOJ 1001】狼抓兔子
    【心情】2016ICPC青岛站打铁记
    【record】11.7..11.13
    Identifying a distributed denial of service (DDOS) attack within a network and defending against such an attack
    在页面所有元素加载完成之后执行某个js函数
    day38 01-Spring框架的概
    day37 10-SH整合的案例练习
    day37 09-Struts2和Hibernate整合环境搭建
  • 原文地址:https://www.cnblogs.com/Tovi/p/6194837.html
Copyright © 2011-2022 走看看