- 博客(26)
- 收藏
- 关注
转载 [LeetCode] 442. Find All Duplicates in an Array
题解来自点击打开链接,vector findDuplicates(vector& nums){ vector res; for(unsigned int i=0;i<nums.size();++i) { nums[abs(nums[i])-1]=-nums[abs(nums[i])-1]; if(nums[abs(nums[i])-1]>0) res.push_back(abs
2017-08-31 23:05:37 164
原创 [LeetCode] 40. Combination Sum II
注意和39题区别,当前层值相同则跳过回溯法void cb2help(vector> &res,vector &v,int target,unsigned int i,vector recp){ if(target<0) return; else if(target==0) { res.push_back(recp); return; } for(unsigned int
2017-08-31 22:39:05 171
原创 [LeetCode] 650. 2 Keys Keyboard
题目链接:点击打开链接dpint minSteps(int n){ vector dp(n+1,1024); dp[1]=0; for(int i=2;i<=n;++i) { for(int k=1;k*k<=i;++k) { if(i%k==0) dp[i]=min(min(dp[k]+i/k,dp[i/k]+k),dp[i]); } } retu
2017-08-31 13:43:29 259
原创 [LeetCode] 39. Combination Sum
回溯void cbhelp(vector> &res,vector &v,int target,int i,vector recp){ if(target<0) return; else if(target==0) { res.push_back(recp); return; } for(unsigned int k=i;k<v.size();++k) { recp.
2017-08-31 12:03:23 206
原创 [LeetCode] 560. Subarray Sum Equals K
int subarraySum2(vector& nums, int k)//use hash{ int sum=0,cnt=0; unordered_map hash; hash[0]=1; for(int x:nums) { sum+=x; cnt+=hash[sum-k]; ++hash[sum]; } return cnt;}
2017-08-30 13:48:51 214
原创 数列最大连续子数组和
分治法:#include <iostream>#include <vector>using namespace std;int A[]={-2,1,-3,4,-1,2,1,-5,4};int CrossSubArray(int A[],int low,int high,int mid){ int left_max=0x80000000; int right_max=0x80
2017-08-27 10:39:49 274
原创 Huffman编码压缩和解压文档,C++实现
关于huffman树及相关算法这里就略过,这里探讨的是如何进行编码和解压缩。先说一下大致步骤 1.首先,读取文档(txt格式),将其存入string类型的变量pretext里 2.进行词频统计 3.创建Huffman树,并以此得到各字符的二进制编码 4.对pretext进行遍历,通过上面得到编码表,将其转化为二进制字符串code,这个二进制串可能十分长 5.将二进制串进行八位一编码,得到压
2017-08-24 17:37:13 666
原创 201703-4 地铁修建 ccf
问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁。 地铁由很多段隧道组成,每段隧道连接两个交通枢纽。经过勘探,有m段隧道作为候选,两个交通枢纽之间最多只有一条候选的隧道,没有隧道两端连接着同一个交通枢纽。 现在有n家隧道施工的公司,每段候选的隧道只能由一个公司施工,每家公司施工需要的天数一致。而每家公司最多只
2017-08-22 22:27:51 768
原创 最小生成树 kruskal算法 C++实现
#include <iostream>#include <vector>#include <algorithm>#define Inf 0x7fffffffusing namespace std;struct node{ int u,v; int w; node(int a,int b,int x):u(a),v(b),w(x){}};vector<node>
2017-08-22 21:46:34 2284
原创 最小生成树 prim算法 C++实现
#include <iostream>#include <vector>#define Inf 0x7fffffffusing namespace std;int main(){ int n,m;//节点个数和边数 cin>>n>>m;//输入节点个数和边数; vector<vector<int>&...
2017-08-22 21:10:01 1667
原创 201412-4 最优灌溉 ccf
问题描述 雷雷承包了很多片麦田,为了灌溉这些麦田,雷雷在第一个麦田挖了一口很深的水井,所有的麦田都从这口井来引水灌溉。 为了灌溉,雷雷需要建立一些水渠,以连接水井和麦田,雷雷也可以利用部分麦田作为“中转站”,利用水渠连接不同的麦田,这样只要一片麦田能被灌溉,则与其连接的麦田也能被灌溉。 现在雷雷知道哪些麦田之间可以建设水渠和建设每个水渠所需要的费用(注意不是所有麦田之间都可以建立水渠)。
2017-08-22 15:23:48 385
原创 201509-4 高速公路 ccf
问题描述 某国有n个城市,为了使得城市间的交通更便利,该国国王打算在城市之间修一些高速公路,由于经费限制,国王打算第一阶段先在部分城市之间修一些单向的高速公路。 现在,大臣们帮国王拟了一个修高速公路的计划。看了计划后,国王发现,有些城市之间可以通过高速公路直接(不经过其他城市)或间接(经过一个或多个其他城市)到达,而有的却不能。如果城市A可以通过高速公路到达城市B,而且城市B也可以通过高
2017-08-22 13:56:18 488
原创 强连通分量 tarjan算法 C++实现
#include <iostream>#include <vector>#include <stack>using namespace std;vector<int> v[100];stack<int> stk;int DFN[100],LOW[100];int index;bool vis[100];void TarJan(int u){ DFN[u]=LOW[u]=+
2017-08-22 13:35:08 2341
原创 201512-4 送货 ccf
问题描述 为了增加公司收入,F公司新开设了物流业务。由于F公司在业界的良好口碑,物流业务一开通即受到了消费者的欢迎,物流业务马上遍及了城市的每条街道。然而,F公司现在只安排了小明一个人负责所有街道的服务。 任务虽然繁重,但是小明有足够的信心,他拿到了城市的地图,准备研究最好的方案。城市中有n个交叉路口,m条街道连接在这些交叉路口之间,每条街道的首尾都正好连接着一个交叉路口。除开街道的首尾
2017-08-21 23:48:16 804 1
原创 you-get 使用总结
you-get 是py上一个方便的下载工具项目主页:https://github.com/soimort/you-get You-Get 主页:https://you-get.org/ You-Get 原版中文说明:https://github.com/soimort/you-get/wiki/中文说明/ 作者:soimort安装: 未安装python事先安装python,安装py最新版本
2017-08-18 09:33:23 23309
原创 [LeetCode] 4.Median of Two Sorted Arrays
原题链接:Median of Two Sorted Arrays 题目大意是,给你两个已经排好序的数组,找到这两个数组的中位数 比如:Example 1:nums1 = [1, 3]nums2 = [2]The median is 2.0又比如:Example 2:nums1 = [1, 2]nums2 = [3, 4]The median is (2 + 3)/2 = 2.5问题可以延
2017-08-17 13:36:05 207
原创 将有序单链表转化为平衡二叉树
109. Convert Sorted List to Binary Search Treestruct TreeNode* constr(struct ListNode* head,struct ListNode* tail){ if(head==tail) return NULL; struct ListNode *mid=head,*temp=head; while(
2017-08-14 17:07:47 1324
原创 34. Search for a Range
34. Search for a Rangeint findLeft(int *nums,int s,int e,int target){ int i=s,j=e,m=0,idx=-1; while(i<=j) { m=(i+j)/2; if(nums[m]<target) i=m+1; else j=m-1;
2017-08-14 13:59:32 208
原创 1105. Spiral Matrix (25)
1105. Spiral Matrix (25)#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>using namespace std;int matrix[10000+1][10000+1];void getMandN(int &m,int &n,int nu
2017-08-08 09:10:45 224
原创 1109. Group Photo (25)
1109. Group Photo (25)#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>using namespace std;struct person{ string name; int height; person(string
2017-08-07 20:44:17 230
原创 1124. Raffle for Weibo Followers (20)
1124. Raffle for Weibo Followers (20)#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>using namespace std;int main(){ int m,n,s; vector<string> v;
2017-08-07 19:48:30 241
原创 1125. Chain the Ropes (25)
1125. Chain the Ropes (25)#include <iostream>#include <vector>#include <algorithm>using namespace std;int main(){ int n; vector<double> v; cin>>n; while(n--) { double t
2017-08-07 19:14:30 234
原创 mathematica抓取网页
一个简易的获取网页.nb程序list = List[];url = "http://blog.csdn.net/gl486546/article/category/6389727/";catchPageElem[n_] := Block[{xml, len, d, i, temp}, xml = Import[url <> ToString[n], "XMLObject"]; d = C
2017-08-07 18:14:15 2069
原创 合并k个有序链表
23. Merge k Sorted Listsstruct ListNode* mergeTwoLists(struct ListNode *l1,struct ListNode *l2){ if(l1==NULL) return l2; if(l2==NULL) return l1; if(l1->val<l2->val) { l1->next=
2017-08-07 13:00:45 357
原创 合并两个有序链表,递归实现
21. Merge Two Sorted Lists 注:代码来自leetcodestruct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) { if(l1==NULL) return l2; if(l2==NULL) return l1; if(l1->val<l2->val)
2017-08-07 12:00:43 481
原创 移去链表倒数第n个节点
19. Remove Nth Node From End of Liststruct ListNode* removeNthFromEnd(struct ListNode* head, int n) { struct ListNode *L=(struct ListNode *)malloc(sizeof(struct ListNode)); L->next=head; st
2017-08-07 11:17:10 325
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人