POJ 2769 Reduced ID Numbers
Reduced ID Numbers
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 8197 | Accepted: 3300 |
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
数论问题,同余、剩余类相关的问题,其实比较简单啦,只要暴力搜一下就可以了~~
如POJ上Discuss所说的,标记数组要开小,不然TLE,TLE,TLE……
[C++]
1 #include<iostream> 2 #include<cstring> 3 4 using namespace std; 5 bool mentioned[100000]; 6 long num[310]; 7 8 int main() 9 { 10 long n; 11 cin>>n; 12 while(n--) 13 { 14 long g,ans; 15 16 cin>>g; 17 for(long i=0;i<g;i++) 18 cin>>num[i]; 19 ans=g; 20 while(true) 21 { 22 int i; 23 memset(mentioned,false,sizeof(mentioned)); 24 for(i=0;i<g;i++) 25 { 26 if(mentioned[num[i]%ans]) 27 break; 28 mentioned[num[i]%ans]=true; 29 } 30 if(i==g) 31 break; 32 ans++; 33 } 34 cout<<ans<<endl; 35 } 36 37 return 0; 38 }


浙公网安备 33010602011771号