poj 2769 Reduced ID Numbers(memset使用技巧)
2016-01-27 12:54
429 查看
DescriptionT. 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 identificationwithin 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.InputOn 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 containone SIN. The SINs within a group are distinct, though not necessarily sorted.OutputFor 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 987651Sample Output
1 8
代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int t[310]; bool vis[1000010]; int main() { int n; scanf("%d",&n); while(n--) { int m,i,j; scanf("%d",&m); for(i=1;i<=m;i++) cin>>t[i]; for(i=m;;i++) { memset(vis,false,i*sizeof(vis[0])); //时间172ms for(j=1;j<=m;j++) //memset(vis,false,sizeof(vis)); tle if(vis[t[j]%i]) break; else vis[t[j]%i]=true; if(j>m) break; } printf("%d\n",i); } return 0; }
相关文章推荐
- oracle sql
- 【转】Oracle 调试 显示长字符串 long value
- UV 自动化展开
- Android-AsyncTask及UncaughtExceptionHandler捕获全局性异常(ANR、FC)
- iPhone屏幕尺寸、分辨率及适配
- iOS设置textView的placeholder
- Rdesktop
- 《从零开始学Swift》学习笔记(Day 65)——Cocoa Touch设计模式及应用之选择器
- IOS笔记
- Appcan学习手记(1)——初探
- 轻量级分布式 RPC 框架
- RFC1939 POP3协议 中文版 (转载)
- Apache 的知识点
- Subsets -- LeetCode
- xampp修改MySQL密码
- 《从零开始学Swift》学习笔记(Day 65)——Cocoa Touch设计模式及应用之选择器
- [读书笔记]互联网+:传统企业的自我颠覆、组织重构、管理进化与互联网转型
- 拨打国际电话
- POJ 3126 Prime Path BFS搜索
- 华为十年:从DBA到副总裁的辛酸与喜悦