CODEVS1533 互斥的数(哈希表)
给定一个集合,要求一个最大子集,满足两两之间不互斥。对两个数x,y互斥的定义是,y=p*x。
先对集合中的数从小到大排序后线性扫,若一个数x可以取则取,取完之后p*x这个数不可取。由于数字较大,使用哈希表来判断。
Program CODEVS1533;
const maxn=;
var a,f:array[..maxn] of longint;
num,m,n,i,j,k,x,y,z:longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div ];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
procedure insert(x:longint);
var h:longint;
begin
h:=x mod maxn;
while (f[h]<>) and (f[h]<>x) do
h:=(h+) mod maxn;
f[h]:=x;
end;
function find(x:longint):boolean;
var h:longint;
begin
h:=x mod maxn;
while (f[h]<>) and (f[h]<>x) do
h:=(h+) mod maxn;
if f[h]= then exit(false) else exit(true);
end;
begin
readln(n,m);
for i:= to n do read(a[i]);
sort(,n);
num:=;
for i:= to n do
begin
if find(a[i]) then continue;
inc(num);
insert(a[i]*m);
end;
writeln(num);
end.
CODEVS1533 互斥的数(哈希表)的更多相关文章
- Junit 注解 类加载器 .动态代理 jdbc 连接池 DButils 事务 Arraylist Linklist hashset 异常 哈希表的数据结构,存储过程 Map Object String Stringbufere File类 文件过滤器_原理分析 flush方法和close方法 序列号冲突问题
Junit 注解 3).其它注意事项: 1).@Test运行的方法,不能有形参: 2).@Test运行的方法,不能有返回值: 3).@Test运行的方法,不能是静态方法: 4).在一个类中,可以同时定 ...
- 查找->动态查找表->哈希表
文字描述 哈希表定义 在前面讨论的各种查找算法中,都是建立在“比较”的基础上.记录的关键字和记录在结构中的相对位置不存在确定的关系,查找的效率依赖于查找过程中所进行的比较次数.而理想的情况是希望不经过 ...
- 167. 两数之和 II - 输入有序数组 + 哈希表 + 双指针
167. 两数之和 II - 输入有序数组 LeetCode_167 题目描述 方法一:暴力法(使用哈希表) class Solution { public int[] twoSum(int[] nu ...
- leetcode 刷题(数组篇)1题 两数之和(哈希表)
题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标. 你可以假设每种输入只会对应一个答案.但是,数组中同一个元 ...
- Java 哈希表运用-LeetCode 1 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- python数据结构与算法——哈希表
哈希表 学习笔记 参考翻译自:<复杂性思考> 及对应的online版本:http://greenteapress.com/complexity/html/thinkcomplexity00 ...
- hdu acm 1425 sort(哈希表思想)
sort Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 深入理解PHP内核(六)哈希表以及PHP的哈希表实现
原文链接:http://www.orlion.ga/241/ 一.哈希表(HashTable) 大部分动态语言的实现中都使用了哈希表,哈希表是一种通过哈希函数,将特定的键映射到特定值得一种数据 结构, ...
- noip模拟赛 好元素 哈希表的第一题
这是一道关于 题2好元素 2s [问题描述] 小A一直认为,如果在一个由N个整数组成的数列{An}中,存在以下情况: Am+An+Ap = Ai (1 <= m, n, p < i < ...
随机推荐
- 服务订单SO创建
FUNCTION Z_SD_SALESORDER_CREATE. *"------------------------------------------------------------ ...
- linux apache 自动监护脚本
1 首先安装curl yum install curl 2 编写shell vi restart_apache.sh 写入一下内容 #!/bin/bashURL="http://127.0. ...
- spring的bean管理
1.所有的类都可以交给Spring管理 2.如何把一个类交给bean管理? (1)配置applicationContext.xml (2)在xml中写入bean节点配置要交给bean管理的类 3.程序 ...
- android 启动时的短暂黑屏解决
http://blog.csdn.net/lonely_fireworks/article/details/22291835 http://www.cnblogs.com/henanjing/arch ...
- mysql linux备份shell
#!/bin/bash# export and backup the activity.sql mysqldump -uname -password activity --skip-lock-ta ...
- 使用Vibrator控制手机振动
import android.os.Bundle;import android.os.Vibrator;import android.app.Activity;import android.app.S ...
- 0302IT行业就业&软件工程之我所思和所想
阅读以下文章 http://www.thea.cn/news/terminal/9/9389.html http://www.shzhidao.cn/system/2015/09/22/0102610 ...
- PHP安装pthreads多线程扩展教程[windows篇]
from:http://blog.csdn.net/aoyoo111/article/details/19020161 一.判断PHP是ts还是nts版 通过phpinfo(); 查看其中的 Thre ...
- C# Lodop实现打印
项目的Debug文件夹下有个template文件夹,里面有用到的js.自己建的要打印的网页和用到的背景图 1.打印方法: class print { public void printzb(strin ...
- php头像上传并裁剪支持3个尺寸
源码下载