![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C / C++
zerokk9912
这个作者很懒,什么都没留下…
展开
-
swap之vector的特化
最近遇到了vector的swap的操作,此前对于该部分并没有了解过,此处主要是通过实验、阅读源码以及网上一些博客后进行总结关于swap此处写了个非常简单的demo#include <iostream>#include <vector>using namespace std;void printVec(const vector<int> &vec) { cout << "vector members: "; for(a.原创 2020-08-16 15:44:26 · 337 阅读 · 0 评论 -
LeetCode: 87. Scramble String
87. Scramble String题目 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": ...原创 2018-11-06 19:31:16 · 118 阅读 · 0 评论 -
LeetCode: 63. Unique Paths II
63. Unique Paths II题目A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot i...原创 2018-11-06 13:34:32 · 141 阅读 · 0 评论 -
LeetCode: 72. Edit Distance
72. Edit Distance题目Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a cha...原创 2018-10-30 20:06:42 · 189 阅读 · 0 评论 -
LeetCode: 55. Jump Game
55. Jump Game题目Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position...原创 2018-10-26 15:43:32 · 153 阅读 · 0 评论 -
LeetCode: 330. Patching Array
330. Patching Array题目Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some el...原创 2018-10-26 12:03:27 · 231 阅读 · 0 评论 -
LeetCode:210. Course Schedule II
题目There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a...原创 2018-10-16 23:56:26 · 147 阅读 · 0 评论 -
LeetCode:134. Gas Station
134. Gas Station题目There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel f...原创 2018-10-18 13:49:00 · 128 阅读 · 0 评论 -
LeetCode:64. Minimum Path Sum
64. Minimum Path Sum题目Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only m...原创 2018-09-28 20:27:51 · 105 阅读 · 0 评论 -
LeetCode: 32. Longest Valid Parentheses
32. Longest Valid Parentheses题目Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: &quot;(()&quot;Output: ...原创 2018-11-04 17:44:16 · 141 阅读 · 0 评论 -
LeetCode: 95. Unique Binary Search Trees II
95. Unique Binary Search Trees II题目 Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...&amp;nbsp;n. Example: Input: 3 Output: [ &amp;nbsp;...原创 2018-11-13 19:32:42 · 125 阅读 · 0 评论 -
A*算法总结
源代码传送门文章目录A*算法导言利用A*算法解决八数码问题八数码问题 比较两种估计函数测试对比验证h1(n)的单调性以及验证凡A*算法挑选出来求后继的点n必定满足 `h(ni)≤1+h(nj)`利用A*算法求解九数码问题能否达到目标状态的判断方法A*算法A* 算法,A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法,也是解决许多搜索问题的有效算法。算法中的距离估算...原创 2019-01-24 23:21:25 · 2280 阅读 · 0 评论 -
LeetCode: 132. Palindrome Partitioning II
132. Palindrome Partitioning II题目Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.Example:...原创 2018-12-06 16:02:01 · 147 阅读 · 0 评论 -
LeetCode: 57. Insert Interval
57. Insert Interval题目Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to the...原创 2018-12-06 14:56:43 · 151 阅读 · 0 评论 -
LeetCode: 123. Best Time to Buy and Sell Stock III
123. Best Time to Buy and Sell Stock III题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple...原创 2018-12-02 16:33:39 · 2329 阅读 · 0 评论 -
LeetCode: 115. Distinct Subsequences
题目Given a string S and a string T, count the number of distinct subsequences of Swhich equals T.A subsequence of a string is a new string which is formed from the original string by deleting some ...原创 2018-11-24 20:50:29 · 114 阅读 · 0 评论 -
LeetCode: 97. Interleaving String
97. Interleaving String题目 Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = &amp;quot;aabcc&amp;quot;, s2 = &amp;quot;dbbca&amp;quot;, s3 = &amp;quot;aadbbc原创 2018-11-16 22:37:12 · 141 阅读 · 0 评论 -
LeetCode: 120. Triangle
120. Triangle题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ ...原创 2018-11-20 20:38:47 · 137 阅读 · 0 评论 -
LeetCode:332. Reconstruct Itinerary
332. Reconstruct Itinerary题目Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a ma...原创 2018-10-07 13:14:13 · 255 阅读 · 0 评论 -
LeetCode:207. Course Schedule
207. Course Schedule题目There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, whi...原创 2018-10-12 23:58:25 · 162 阅读 · 0 评论 -
LeetCode:785. Is Graph Bipartite?
785. Is Graph Bipartite?题目Given an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets A a...原创 2018-10-12 00:12:30 · 155 阅读 · 0 评论 -
Binary Tree 遍历
Binary Tree 的 访问递归实现简单介绍: 先序遍历:对一棵二叉树的前序遍历,先访问根结点,再访问左子树,然后访问右子树。void preorder(Treenode *p) { if (p != NULL){ visit(p); // visit泛指要对节点进行的操作 preorder(p-&amp;g...原创 2018-05-24 20:50:58 · 264 阅读 · 0 评论 -
Dijkstra 算法 -方法、算法、代码和正确性的证明
Dijkstra 算法 -方法、算法、代码和正确性的证明 摘要本文介绍Dijkstra算法,包括方法、算法、正确性的证明和算法C++的实现。§1 Dijkstra算法方法介绍算法适用范围:Dijkstra算法解决的是带权重的问题的有向图上单源最短路径问题,该算法要求所有边的权重都为非负值。D原创 2017-06-09 19:40:29 · 3576 阅读 · 0 评论 -
最小生成树MST -- Prim 算法实现
最小生成树MST最小生成树定义:一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边。Prim algorithm: Prim算法简述 1).输入:一个加权连通图,其中顶点集合为V,边集合为E; 2).初始化:Vnew= {x},其中x为集合V中的任一节点(起始点),Enew= {},为空; 3).重复下列操作,直到原创 2017-05-20 20:28:25 · 538 阅读 · 0 评论 -
LeetCode:310. Minimum Height Trees
310. Minimum Height Trees题目For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those wi...原创 2018-09-30 22:31:51 · 331 阅读 · 0 评论 -
操作系统 - C语言实现读者写者问题(写者优先)
同步互斥问题 - 读者写者问题之写者优先问题要求:读者-写者问题的读写操作限制(仅读者优先或写者优先): 写-写互斥,即不能有两个写者同时进行写操作。读-写互斥,即不能同时有一个线程在读,而另一个线程在写。读-读允许,即可以有一个或多个读者在读。写者优先的附加限制:如果一个读者申请进行读操作时已有另一写者在等待访问共享资源,则该读者必须等到没有写者处于等待状态后才能开始读操作。...原创 2018-05-30 10:59:36 · 50549 阅读 · 40 评论 -
操作系统 - C语言实现读者写者问题(读者优先)
同步互斥问题 - 读者写者问题之读者优先问题要求:读者-写者问题的读写操作限制(仅读者优先或写者优先): 写-写互斥,即不能有两个写者同时进行写操作。读-写互斥,即不能同时有一个线程在读,而另一个线程在写。读-读允许,即可以有一个或多个读者在读。读者优先的附加限制:如果一个读者申请进行读操作时已有另一个读者正在进行读操作,则该读者可直接开始读操作。读者优先实现思路: ...原创 2018-05-30 10:50:56 · 17489 阅读 · 19 评论 -
操作系统 - C语言实现生产者消费者问题
同步互斥问题 - 生产者消费者问题问题描述:有多个进程:多个生产者进程和多个消费者进程共享一个初始为空、固定大小为n的缓存(缓冲区)。生产者的工作是制造数据,只有缓冲区没满时,生产者才能把消息放入到缓冲区,否则必须等待; 同时,只有缓冲区不空时,消费者才能从中取出消息,一次消费一段数据(即将其从缓存中移出),否则必须等待。由于缓冲区是临界资源,它只允许一个生产者放入消息,或者一个消...原创 2018-05-30 10:34:29 · 19733 阅读 · 9 评论 -
贪吃蛇 snake
c语言版贪吃蛇全局设置//设置#define SNAKE_MAX_LENGTH 20#define SNAKE_HEAD 'H'#define SNAKE_BODY 'X'#define BLANK_CELL ' '#define SNAKE_FOOD '$'#define WALL_CELL '*'void snakeMove(int,int);//贪吃蛇的移动 void print(原创 2017-05-21 17:13:56 · 1011 阅读 · 0 评论 -
一致性哈希学习与实现
一致性哈希学习与实现一致性哈希算法的学习基本场景:假设有N个cache服务器,对服务器集群的管理,路由算法至关重要,就和负载均衡算法一样,路由算法决定着究竟该访问集群中的哪台服务器。余数哈希:计算 object 的 hash 值,然后均匀的映射到到 N 个 cache 服务器; hash(object) % N 但是当需要增加或者减少cache服务器的时候,这个算法的问题就暴露...原创 2018-06-18 23:15:41 · 190 阅读 · 0 评论 -
LeetCode:1 Two Sum
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 ...原创 2018-09-05 20:47:44 · 95 阅读 · 0 评论 -
RapidJSON解析和生成Json
RapidJSON学习RapidJSON获取json数据键值对的key和value std::string output = &quot;&quot;;output += &quot;Deck: \n&quot;;// deckfor (unsigned j = 0; j &amp;lt; (document[&quot;data&quot;])[&quot;原创 2018-06-27 22:47:02 · 4121 阅读 · 0 评论 -
LeetCode:8. String to Integer (atoi)
8. String to Integer (atoi)题目 Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character...原创 2018-09-13 15:30:12 · 129 阅读 · 0 评论 -
LeetCode:50. Pow(x, n)
50. Pow(x, n)题目Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input:...原创 2018-09-26 21:33:07 · 98 阅读 · 0 评论 -
LeetCode:22. Generate Parentheses
22. Generate Parentheses题目Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is:[ &amp;amp;amp;amp;amp;amp;quot;((()))&amp;amp;amp;amp;amp原创 2018-09-20 16:05:52 · 124 阅读 · 0 评论 -
LeetCode:5. Longest Palindromic Substring
5. Longest Palindromic Substring题目Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example Input: &amp;amp;amp;amp;amp;amp;quot;babad&amp;amp;amp;amp;amp;amp;quot; Outp原创 2018-09-18 20:13:35 · 111 阅读 · 0 评论 -
LeetCode:41. First Missing Positive
41. First Missing Positive题目Given an unsorted integer array, find the smallest missing positive integer.Example:Input: [7,8,9,11,12]Output: 1Note: Your algorithm should run in O(n) time and ...原创 2018-09-16 11:00:23 · 163 阅读 · 0 评论 -
LeetCode:3 Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters题目 Given a string, find the length of the longest substring without repeating characters. Input: “pwwkew” Output: 3 Explanation: The...原创 2018-09-09 13:50:20 · 123 阅读 · 0 评论 -
LeetCode:67 Add Binary
67. Add Binary题目Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0. Input: a = “11”, b = “1” Output...原创 2018-09-06 17:06:01 · 91 阅读 · 0 评论 -
C语言实现的高精度加法
C语言实现的高精度加法主要考虑问题:1.进位的处理 2.细节加减的处理#include <stdio.h>#include <string.h>int main(){ char str1[100000],str2[100000],sum[100010]; scanf("%s %s",str1,str2); int t=0,ans=0,i,j,k=0; for(原创 2017-05-19 23:02:50 · 1978 阅读 · 1 评论