1190.ReducedIDNumbers | |
| Total: | 1418 | Accepted: | 581 | Rating: | 3.5/5.0(4votes) | |
| |
| | |
| | |
| TimeLimit:2sMemoryLimit:32MBDescriptionT.ChurteachesvariousgroupsofstudentsatuniversityU.EveryU-studenthasauniqueStudentIdentificationNumber(SIN).ASINsisanintegerintherange0≤s≤MaxSINwithMaxSIN=106-1.T.ChurfindsthisrangeofSINstoolargeforidentificationwithinhergroups.Foreachgroup,shewantstofindthesmallestpositiveintegerm,suchthatwithinthegroupallSINsreducedmodulomareunique.InputOnthefirstlineoftheinputisasinglepositiveintegerN,tellingthenumberoftestcases(groups)tofollow.EachcasestartswithonelinecontainingtheintegerG(1≤G≤300):thenumberofstudentsinthegroup.ThefollowingGlineseachcontainoneSIN.TheSINswithinagrouparedistinct,thoughnotnecessarilysorted.OutputForeachtestcase,outputonelinecontainingthesmallestmodulusm,suchthatallSINsreducedmodulomaredistinct.SampleInputCopysampleinputtoclipboard2
1
124866
3
124866
111111
987651 SampleOutput1
8 我的笨方法,暴力ac #include<stdio.h>intjudge(intmod[300],intn);intmain(){intt,n,i,j,mod[300],mark=1;longintsin[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;}}intjudge(intmod[300],intn){intk,l; for(k=0;k<n;k++)for(l=k;l<n-1;l++){if(mod[l+1]==mod[k])return0;}return1;} 太慢了,用了,0.36,真不知道前面的那些牛人怎样0.01s的,求方法啊 |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理