1190 Reduced ID Numbers 求更高效的方法
来源:互联网 发布:微信域名入口页 编辑:程序博客网 时间:2024/06/05 03:29
1190. Reduced ID Numbers Total: 1418Accepted:581Rating:3.5/5.0(4 votes)
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的,求方法啊
- 1190 Reduced ID Numbers 求更高效的方法
- sicily 1190 Reduced ID Numbers
- 1190. Reduced ID Numbers (求余)
- Reduced ID Numbers pku2769
- 1190. Reduced ID Numbers
- 1190. Reduced ID Numbers
- POJ2769 Reduced ID Numbers
- sicily1190. Reduced ID Numbers
- 1190. Reduced ID Numbers
- POJ2769 Reduced ID Numbers
- POJ2769 Reduced ID Numbers
- [POJ2769] Reduced ID Numbers
- POJ2769 Reduced ID Numbers 求余应用-暴力
- poj 2769 Reduced ID Numbers
- Sicily 1190. Reduced ID Numbers
- Poj 2769 Reduced ID Numbers
- POJ 2769 Reduced ID Numbers
- POJ 2769 Reduced ID Numbers
- How to set up a Linux OpenVPN client
- JavaScript中延迟指定时间
- ftrace 简介
- Windows下编译memcached-1.4.5(32bit和64bit)
- sicily题目之2001 2005
- 1190 Reduced ID Numbers 求更高效的方法
- sicily 1007
- OSGI学习手册
- QT 使用QProcess 调用外部程序并截取输出流
- 《小强与小明》——正在疯传的伟大的故事
- 移植u-boot-2011.03到S3C2440(utu2440)的方法与步骤###5.使用JLINK间接烧写u-boot至FLASH的方法与步骤
- LumiSoft.Net 读取hotmail指定的邮件
- 那些必须了解的地理信息专业基础概念
- 1813. M进制数问题