哈希
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
LeetCode--532. K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in...原创 2018-06-02 21:18:27 · 160 阅读 · 0 评论 -
PAT甲级A1092 To Buy or Not to Buy (20 分)
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sel...原创 2019-02-23 19:48:27 · 176 阅读 · 0 评论 -
PAT甲级A1078 Hashing (25 分)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSiz...原创 2019-02-18 19:20:08 · 245 阅读 · 0 评论 -
PAT甲级A1107 Social Clusters (30 分)
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of thei...原创 2019-02-26 21:26:05 · 196 阅读 · 0 评论 -
PAT甲级A1124 Raffle for Weibo Followers (20 分)
John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give...原创 2019-03-08 16:25:07 · 185 阅读 · 0 评论 -
PAT乙级B1090 危险品装箱 (25 分)
集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里。比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸。本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否能装在同一只箱子里。输入格式:输入第一行给出两个正整数:N (≤104) 是成对的不相容物品的对数;M (≤100) 是集装箱货品清单的单数。随后数据分两大块给出。第一块有 N 行...原创 2019-03-14 20:29:30 · 403 阅读 · 0 评论 -
PAT甲级A1143 Lowest Common Ancestor (30 分)
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.A binary search tree (BST) is recursively defined as a binary tree which has ...原创 2019-03-15 14:10:44 · 381 阅读 · 0 评论 -
PAT乙级B1095 解码PAT准考证 (25 分)
PAT 准考证号由 4 部分组成:第 1 位是级别,即 T 代表顶级;A 代表甲级;B 代表乙级; 第 2~4 位是考场编号,范围从 101 到 999; 第 5~10 位是考试日期,格式为年、月、日顺次各占 2 位; 最后 11~13 位是考生编号,范围从 000 到 999。现给定一系列考生的准考证号和他们的成绩,请你按照要求输出各种统计信息。输入格式:输入首先在一行中给出...原创 2019-03-16 13:49:21 · 496 阅读 · 0 评论 -
PAT甲级A1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...原创 2019-03-16 15:48:20 · 316 阅读 · 0 评论 -
PAT甲级A1121 Damn Single (25 分)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification:Each inpu...原创 2019-03-08 10:44:23 · 171 阅读 · 0 评论 -
PAT甲级A1063 Set Similarity (25 分)
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of ...原创 2019-01-24 20:10:46 · 182 阅读 · 0 评论 -
LeetCode--888. Fair Candy Swap
Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.Since they are friends, they wo...原创 2019-01-13 21:34:14 · 167 阅读 · 1 评论 -
PAT甲级A1048 Find Coins (25 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2019-01-17 20:49:50 · 212 阅读 · 0 评论 -
LeetCode--219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.E...原创 2018-05-30 21:22:56 · 133 阅读 · 0 评论 -
LeetCode--217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is ...原创 2018-05-30 21:52:56 · 144 阅读 · 0 评论 -
LeetCode--1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...原创 2018-05-30 22:26:53 · 108 阅读 · 0 评论 -
LeetCode--383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot...原创 2018-06-13 21:09:19 · 286 阅读 · 0 评论 -
LeetCode--819. Most Common Word
Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer...原创 2018-07-11 21:27:02 · 190 阅读 · 0 评论 -
PAT甲级A1041 Be Unique(20 分)
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104]. The first one who bets o...原创 2018-08-31 21:15:10 · 153 阅读 · 0 评论 -
PAT甲级A1039 Course List for Student(25 分)
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes ...原创 2018-08-29 22:04:13 · 176 阅读 · 0 评论 -
PAT甲级A1144 The Missing Number(20 分)
1144 The Missing Number(20 分)Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Specification:Each input file contains one test case. Fo...原创 2018-09-03 20:52:28 · 238 阅读 · 0 评论 -
PAT甲级A1145 Hashing - Average Search Time(25 分)
1145 Hashing - Average Search Time(25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys...原创 2018-09-03 22:26:19 · 711 阅读 · 1 评论 -
PAT乙级B1087 有多少不同的值 (20 分)
当自然数 n 依次取 1、2、3、……、N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x 的最大自然数,即 x 的整数部分。)输入格式:输入给出一个正整数 N(2≤N≤104)。输出格式:在一行中输出题面中算式取到的不同值的个数。输入样例:2017输出样例:1480思路:对于任意给定的正整...原创 2019-03-13 15:00:49 · 213 阅读 · 0 评论