您的位置:首页 > 其它

POJ 2769 Reduced ID Numbers

2016-08-23 20:37 381 查看
Reduced ID Numbers

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9897 Accepted: 3946
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

总结:很玄学的一道暴力题,vis如果开到题目要求的(虽然客订到不要那么大)10的六次,那么memset会超时,map居然也会超!?神奇了!

#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
const int maxn=400;
const int maxsin=100000;
int n,a[maxn];
bool vis[maxsin];
int main(int argc, const char * argv[]) {
int T;
cin>>T;
int ans;
while(T--)
{

cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;;i++)
{
memset(vis,0,sizeof(vis));
int flag=1;
for(int j=1;j<=n;j++)
{
int m=a[j]%i;
if(vis[m]==1)
{
flag=0;
break;
}
vis[m]=1;
}
if(flag==1) {ans=i; break;}
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: