POJ 2769 Reduced ID Numbers
2016-08-23 20:37
381 查看
Reduced ID Numbers
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
Sample Output
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 9897 | Accepted: 3946 |
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; }
相关文章推荐
- Android 从相册选取多张照片
- 【校内互侧】Sunshine’s city (lct+线段树)
- Handler Looper Messagequeue Message 细节以及关系
- Docker简介(未完)
- // 组成一个没有重复元素的数组范围是1~10
- 求一个区间有多少个数能整除k
- MyEclipse8.5快速搭建SSH框架
- RN发送接收事件--原生模块
- 深入理解PHP原理之PHP脚本执行原理(1)
- tcpdump
- ASCII-转义字符
- [转]ACM 取石子问题
- 动态添加ImageView控件并在其上实现动画
- AngularJS绑定数据
- 167. Two Sum II - Input array is sorted
- call apply方法
- 数据结构实验之查找四:二分查找
- 中南大学2016年校队选拔赛第一场Problem D
- 167. Two Sum II - Input array is sorted
- 闲聊Oracle Exadata与Hadoop