poj 2769 Reduced ID Numbers 同余定理
链接:http://poj.org/problem?id=2769
题意:寻找数m,是的对于n个数的余数不同
思路:暴力,优化:同余部分不用测试
代码:
#include <iostream>
#include <string.h>
using namespace std;
int ans[],vis[];
int main() {
ios::sync_with_stdio(false);
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,n,i,j,ok;
cin>>t;
while(t--) {
cin>>n;
for(i=; i<=n; ++i) cin>>ans[i];
for(i=; i<; ++i) {
ok=;
for(j=; j<=i-; ++j) vis[j]=;
for(j=; j<=n; ++j) {
if(vis[ans[j]%i]) {
ok=;
break;
}
vis[ans[j]%i]=;
}
if(ok) break;
}
cout<<i<<endl;
}
return ;
}
poj 2769 Reduced ID Numbers 同余定理的更多相关文章
- poj 2769 Reduced ID Numbers(memset使用技巧)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...
- POJ 1465 Multiple (BFS,同余定理)
id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS Memory Limit: 32768K T ...
- G - Reduced ID Numbers(第二季水)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...
- C - Reduced ID Numbers 寒假训练
T. Chur teaches various groups of students at university U. Every U-student has a unique Student Ide ...
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11978 A ...
- POJ 1426 Find The Multiple(数论——中国同余定理)
题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find ...
- POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15767 A ...
- poj 1651 http://poj.org/problem?id=1651
http://poj.org/problem?id=1651Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K To ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
随机推荐
- C++流类库(11)
C++的流类库由几个进行I/O操作的基础类和几个支持特定种类的源和目标的I/O操作的类组成. 流类库的基础类 ios类是isrream类和ostream类的虚基类,用来提供对流进行格式化I/O操作和错 ...
- 使用Xmanager通过XDMCP连接远程Centos 7 (摘自xmanager官方博客)
Using Xmanager to connect to remote CentOS 7 via XDMCP Gnome in CentOS 7 tries to use local hardware ...
- 开源API集成测试工具 Hitchhiker v0.3更新 - 自动同步
Hitchhiker 是一款开源的 Restful Api 集成测试工具,支持Schedule, 数据对比,压力测试,可以轻松部署到本地,和你的team成员一起管理Api. 详细介绍请看: http: ...
- 【JAVA零基础入门系列】Day12 Java类的简单应用
俗话说的好,实践出真知,所以除了理论知识掌握扎实以外,更重要的是要多加操练,这样才能掌握核心科技. 今天我们就用刚学会的类来实践一下,目标便是完成上一篇中的剁手任务. 我们的商品类已经准备好了,代码重 ...
- 删除链表中倒数第n个节点
给定一个链表,删除链表中倒数第n个节点,返回链表的头节点. 样例 给出链表1->2->3->4->5->null和 n = 2. 删除倒数第二个节点之后,这个链表将变成1 ...
- ES6中数组的新方法
数组的扩展 1.1扩展运算符 1.1.1:... 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. <body> < ...
- Linq Take和Skip详解
Take()方法的作用就是:从查询结果中提取前n个结果. Skip()方法正好是Take()方法的反面,它可以跳过前n个结果,返回剩余的结果. 例如:查找年龄最大的3个人 表Student的数据是 N ...
- SVG绘制loading效果
<div class="loading"> <svg width='40px' height='40px' xmlns="http://www.w3.o ...
- 对象作为 handleEvent
elem.addEventListener("click", obj, false); //用对象作为处理函数 var obj = { handleEvent: ...
- HTML学习笔记 CSS学习选择器案例 第五节 (原创) 参考使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...