POJ_2769同余问题
2015-10-31 12:53
375 查看
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: 9310 | Accepted: 3740 |
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
/*poj2769 *题意:给出g个数,求出最小的数使得这g个数模上这最小的数的余数是唯一的 *算法分析:看题目限制时间为2s,第一想法就是扫描了,从1开始到最大的数加1进行扫描, *判断余数是否唯一。是则结束 ,这里注意地方就是不能刚好到最大的数结束、而是到最大的数加1 *结束,我试了下刚好扫到最大的数WA了、、、、 */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <string> #include <cmath> using namespace std; int a[310]; int b[310]; //保存余数 int main() { int t; cin >> t; while (t --) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int n; cin >> n; for (int i = 0; i<n; i++) cin >> a[i]; sort(a, a+n); int p = a[n-1]; int flag = 1, res, flag1 = 1; for (int i = 1; i<=p+1 && flag1; i++) { flag = 1; for (int j = 0; j<n; j++) { b[j] = a[j] % i; } sort(b, b+n); for (int j = 0; j<n-1 && flag; j++) { if (b[j] == b[j+1]) { flag = 0; } } if (flag) { res = i; flag1 = 0; } memset(b, 0, sizeof(b)); } //cout << flag<< endl; //cout << b[0]<< endl<< b[1]<< endl<< b[2]<< endl; cout << res << endl; } return 0; }
不怕脚下的路有多难走、就怕你压根不想走下去、、
相关文章推荐
- 超高端商务,三星手机的另一个掘金场
- HTML学习11:HTTP 方法
- 第九周-项目3-稀疏矩阵的三元组表示的实现及应用
- POJ_2769同余问题
- Linux系统管理命令之用户管理
- 什么是shell,shell基础由浅入深,常用的shell命令、用法、技巧
- @*android 引用
- Hibernate集合映射规则
- Linux打包压缩命令
- 带有语法强类型检查的事件总线(EventBus)框架再完善篇
- android--(动画2_属性动画)
- 18、滑动导航选择
- 数据结构之递归算法
- keepalived构建LVS_DR和Nginx的高可用集群
- Win7 64位系统安装XP共享打印机(适用Win10 x64)
- 17、遮罩
- 错误记录 1
- 16、手势
- 打印机共享类问题
- Git - error: RPC failed; result=22, HTTP code = 401 fatal: The remote end hung up unexpectedly