1190 Reduced ID Numbers 求更高效的方法

来源:互联网 发布:微信域名入口页 编辑:程序博客网 时间:2024/06/05 03:29

1190. Reduced ID Numbers
  
Total: 1418Accepted:581Rating:
3.5/5.0(4 votes)
 

    
Time Limit: 2s Memory Limit: 32MB
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
Copy sample input to clipboard
211248663124866111111987651
Sample Output
18
 
我的笨方法,暴力ac
#include<stdio.h>
int judge(int mod[300],int n);
int main()
{
int t,n,i,j,mod[300],mark=1;
long int sin[300];
scanf("%d",&t);
while(t--)
{

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&sin[i]);
if(n==1)
{printf("%d/n",1);
continue;}

for(i=2;mark==1;i++)
{
for(j=0;j<n;j++)
mod[j]=sin[j]%i;

if(judge(mod,n))
mark=0;
}
  
printf("%d/n",i-1);
mark=1;
for(i=0;i<n;i++)
mod[i]=sin[i]=0;

}

}
int judge(int mod[300],int n)
{
int k,l;
       for(k=0;k<n;k++)
for(l=k;l<n-1;l++)
{
if(mod[l+1]==mod[k])
return 0;
}
return 1;
}
 
 
 
太慢了,用了,0.36,真不知道前面的那些牛人怎样0.01s的,求方法啊