- 博客(79)
- 收藏
- 关注
原创 性能最好的字符串转64位Hash函数
问题:两个海量字符串数据集,在内存有限、不能生成中间文件的前提下,如何求出它们的交集?答:将字符串转换成数字处理。本文包含6种一次hash冲突概率极低的hash函数,其性能比较为 CityHash64>FarmHash64>Murmur3>Murmur2_64A>Murmur2_64B>Blizzard_MPQ第6名 - Blizzard_MPQ#include <bits/stdc++.h>using namespace std;using ui = unsigned int;us
2021-05-10 22:05:56 2682
原创 fread不分段读取文件(.txt / .csv)
文件在Excel中显示在记事本和Notepad中显示代码#include <bits/stdc++.h>using namespace std;const char *input_file_name = "input.csv";void read(){ FILE* pFILE = fopen(input_file_name, "r"); fseek(pFILE, 0, SEEK_END); int file_size = ftell(pFILE); char
2021-04-30 08:27:22 340
原创 fread分段读取文件(.txt / .csv)
文件Excel中显示记事本和Notepad中显示代码#include <bits/stdc++.h>using namespace std;const char *input_file_name = "input.csv";const int buf_size = 10*1024*1024; //一次读10MBstatic char buffer[buf_size];void read(){ FILE* pFILE = fopen(input_file_name,
2021-04-30 08:15:52 1724
原创 C++写入文件(.txt / .csv)
代码#include <bits/stdc++.h>using namespace std;const char *input_file_name = "input.csv";void write(){ ofstream outFile; int cnt = 1; //input outFile.open(input_file_name, ios::out); outFile << cnt++ << ',' << "\"芯片\""
2021-04-30 08:07:25 455 2
原创 mmap读入文件(.txt / .csv)
#include <bits/stdc++.h>#include <sys/mman.h>#include <fcntl.h>#include <unistd.h>using namespace std;const char *input_file_name = "input.csv";void read(){ int fd = open(input1_file_name, O_RDONLY); int buf_size = lsee
2021-04-30 08:00:40 364
原创 2021华为软件精英挑战赛总结
杭厦赛区64弱选手的初赛之旅一、前言二、思路预处理填充策略购买策略迁移策略三、代码A榜1102891453无调参四、来年再战一、前言去年大二,在近似满课和C++连vector都不知道是啥的基础上,经过一个月和队友的现学,我负责数据结构和算法、队友负责IO和多线程,最终获得杭厦初赛正赛26(单线程)复赛正赛第9(多线程)的成绩。今年壮志凌云,想着冲击一下全国总决赛,结果理想很丰满现实很骨感。这次题目更拼思路和灵感,队内配合不好,近似单挑地完成了比赛,最后没有进入复赛,止步64弱,很遗憾。3月13号考
2021-04-10 11:18:28 3505
原创 2021年3月春季PAT甲级满分总结(附考场代码)
分享一些备考的经验和经历一、考试经历考前准备考前小状况线上考试步骤二、题解(考场原版代码)1、 Arithmetic Progression of Primes2、Lab Access Scheduling3、Structure of Max-Heap4、Recycling of Shared Bicycles三、总结一、考试经历本次线上考试100分,一个半小时左右AK(退系统前看了下排名我是第22个满分),四道题分别是dfs、区间贪心模板题、堆、flyod模板题,没有去年那样的坑人题目,算是正常难度吧
2021-03-15 23:08:36 3949 14
原创 【剑指紫金港】1059 Prime Factors
A 1059 Prime Factors题目链接Problem DescriptionGiven any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1 k1 ×p2 k2 ×⋯×pm km .InputEach input file contains one test case
2021-03-03 12:56:19 71
原创 【剑指紫金港】1045 Favorite Color Stripe 贪心
A 1045 Favorite Color Stripe题目链接Problem DescriptionEva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts t
2021-02-28 12:21:38 69
原创 【剑指紫金港】1145 Hashing - Average Search Time 平方探查法
A 1145 Hashing - Average Search Time题目链接Problem DescriptionThe 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 from the table and output the avera
2021-02-17 13:26:18 145
原创 【剑指紫金港】1143 Lowest Common Ancestor
A 1143 Lowest Common Ancestor题目链接Problem DescriptionThe 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 th
2021-02-17 10:32:06 60
原创 【剑指紫金港】1136 A Delayed Palindrome 字符串骚操作
A 1136 A Delayed Palindrome题目链接Problem DescriptionConsider a positive integer N written in standard notation with k+1 digits ai as ak ⋯a1 a0 with 0≤ai <10 for all i and ak >0. Then N is palindromic if and only if ai =ak−i
2021-02-15 17:24:57 80
原创 【剑指紫金港】1131 Subway Map 地铁乘车规划
A 1131 Subway Map题目链接Problem DescriptionIn the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer sk
2021-02-15 00:08:02 162
原创 【剑指紫金港】1129 Recommendation System Set妙用
A 1129 Recommendation System题目链接Problem DescriptionRecommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by the number of times
2021-02-14 20:40:20 76
原创 【剑指紫金港】1123 Is It a Complete AVL Tree 完全AVL树模板
A 1123 Is It a Complete AVL Tree题目链接Problem DescriptionAn AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing
2021-02-13 16:16:24 80
原创 【剑指紫金港】1119 Pre- and Post-order Traversals 全网最易懂的非递归版
A 1119 Pre- and Post-order Traversals题目链接Problem DescriptionSuppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and i
2021-02-13 10:29:12 134
原创 【剑指紫金港】1117 Eddington Number 大年初一第一篇!
A 1117 Eddington Number题目链接Problem DescriptionBritish astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an “Eddington number”, E – that is, the maximum integer E such that it is for E days tha
2021-02-12 20:22:14 80
原创 【剑指紫金港】1112 Stucked Keyboard
A 1112 Stucked Keyboard题目链接Problem DescriptionOn a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.Now given a resulting stri
2021-02-10 22:28:01 105
原创 【剑指紫金港】1110 Complete Binary Tree 完全二叉树静态实现
A 1110 Complete Binary Tree题目链接Problem DescriptionGiven a tree, you are supposed to tell if it is a complete binary tree.InputEach input file contains one test case. For each case, the first line gives a positive integer N (≤20) which is the total num
2021-02-10 12:26:05 122
原创 【剑指紫金港】1108 Finding Average(sscanf和sprintf)
A 1108 Finding Average题目链接Problem DescriptionThe basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real number
2021-02-09 22:07:58 81
原创 【剑指紫金港】1103 Integer Factorization N皇后思想
A 1103 Integer Factorization题目链接Problem DescriptionThe K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization of N for any positive i
2021-02-09 20:36:18 365
原创 【剑指紫金港】1105 Spiral Matrix 贪吃蛇算法
A 1105 Spiral Matrix题目链接Problem DescriptionThis time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwi
2021-02-09 16:04:36 89
原创 【剑指紫金港】1104 Sum of Number Segments
A 1104 Sum of Number Segments题目链接Problem DescriptionGiven a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3)
2021-02-09 15:57:24 49
原创 【剑指紫金港】1099 Build A Binary Search Tree 根据BST的结构求层序
A 1099 Build A Binary Search Tree题目链接Problem DescriptionA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right s
2021-02-08 15:50:58 70
原创 【剑指紫金港】1096 Consecutive Factors 阶乘
A 1096 Consecutive Factors题目链接Problem DescriptionAmong all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given any
2021-02-08 11:58:50 65
原创 【剑指紫金港】1085 Perfect Sequence
A 1085 Perfect Sequence题目链接Problem DescriptionGiven a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respectively.N
2021-02-07 17:28:06 48
原创 【剑指紫金港】1086 Tree Traversals Again 已知先序中序求后序
A 1086 Tree Traversals Again题目链接Problem DescriptionAn inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack
2021-02-07 16:19:18 62
原创 【剑指紫金港】1076 Forwards on Weibo BFS和DFS我都可
A 1076 Forwards on Weibo题目链接Problem DescriptionWeibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user m
2021-02-06 10:56:22 63
原创 【剑指紫金港】1088 Rational Arithmetic 分数计算
A 1088 Rational Arithmetic题目链接Problem DescriptionFor two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.InputEach input file contains one test case, which gives in o
2021-02-04 23:38:48 90
原创 【剑指紫金港】1064 Complete Binary Search Tree 填空完全二叉搜索树
A 1064 Complete Binary Search Tree题目链接Problem DescriptionA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right
2021-02-03 23:42:07 107
原创 【剑指紫金港】1051 Pop Sequence 栈模拟
A 1051 Pop Sequence题目链接Problem DescriptionGiven a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For
2021-02-02 22:36:57 106
原创 【剑指紫金港】1044 Shopping in Mars 区间查询二分搜索优化
A 1044 Shopping in Mars题目链接Problem DescriptionShopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for onl
2021-02-01 22:31:40 79
原创 【剑指紫金港】1043 Is It a Binary Search Tree 二叉搜索树
题目标题题目链接Problem DescriptionInputOutputSample Input:ASample Output:2题目大意:牛解题思路:龙AC代码#include<bits/stdc++.h>using namespace std;
2021-02-01 16:17:45 116
原创 【剑指紫金港】1040 Longest Symmetric String DP回文字符串
A 1040 Longest Symmetric String DP回文字符串题目链接Problem DescriptionGiven a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, h
2021-02-01 11:02:58 87
原创 【剑指紫金港】1039 Course List for Student 字符串转int映射
A 1039 Course List for Student题目链接Problem DescriptionZhejiang 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
2021-02-01 00:01:04 63
原创 【剑指紫金港】1038 Recover the Smallest Number 玄学
A 1038 Recover the Smallest Number(CMP函数的玄学运用)题目链接Problem DescriptionGiven a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like
2021-01-31 23:18:08 68
原创 【剑指紫金港】1033 To Fill or Not to Fill 贪心
A 1033 To Fill or Not to Fill(官网+牛客全AC)题目链接Problem DescriptionWith highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Dif
2021-01-31 11:43:49 89 1
原创 【剑指紫金港】1030 Travel Plan Dijsktra+路径筛选记录
A 1030 Travel Plan(模板题)题目链接Problem DescriptionA traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between
2021-01-30 13:30:23 76
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人