自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 资源 (1)
  • 收藏
  • 关注

原创 最大公约数最小公倍数

1.求两个数的最大公约数int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } 2.求两个数的最小公倍数int lcm(int a, int b){ return a*b/gcd(a,b);}3.n个数的最大公约数int ngcd(vec...

2018-10-05 21:49:16 143

原创 Maximal Rectangle

1.原题链接:https://leetcode.com/problems/maximal-rectangle/description/Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.2.分析:(1)学习...

2018-09-18 15:39:16 136

原创 [hihocoder1198] Memory Allocating Algorithm

链接:https://hihocoder.com/problemset/problem/1198?sid=1370091思路:(1)直接模仿内存分配方式。定义Node(bg,ed,val),bg表示分配内存的开始index,ed表示结束下表(不含),val表示id;(2)维护两个list,已分配used,空闲freed;(3)不变性:保证freed空闲块是递增的,每次插入新的空闲节...

2018-09-13 10:50:56 161

原创 [hihocoder]1334 : Word Construction

题目链接:https://hihocoder.com/problemset/problem/1334?sid=1369471思路:(1)把单词想象成一个个节点,两个节点若有共同的字母则这两个节点间有一条边,所有节点构成一个图。每个节点有一个度记录该节点与多少个节点相连接,则问题转化为去除最少的节点,使得图中所有节点的度为0;(2)为了方便统计与节点有共同字母的其他节点,使用unorde...

2018-09-11 15:50:31 142

原创 [hihocoder]1238 : Total Highway Distance

题目:https://hihocoder.com/problemset/problem/1238?sid=1369284一道很不错的题目。思路:对于任意一条边(a,b),权值为w,以a为根的子树节点数目为node[a],以b为根的子树节点node[b],则该边被计算node[a]*node[b]*w次。利用DFS对所有节点进行遍历。#include <iostream>...

2018-09-10 21:40:54 133

原创 [hihocoder]1099 : Constellations

原题链接:https://hihocoder.com/problemset/problem/1099?sid=1368206分析:(1)由于最后才给出天空坐标,先将星图保存起来,获得sky后再检查各个星座是否能被发现;(2)对于每张星图,保存第一个星星坐标,后续星星保存其与第一个星星的相对位置;(3)检查每张星图:对sky每个星星坐标,通过(2)中的相对位置检查是否存在;(4)...

2018-09-08 16:01:10 171

原创 最大乘积子数组

问题:Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.思路:看了这篇文章https://leetcode.com/problems/maximum-product-s...

2018-09-02 16:21:34 207

原创 枚举类问题总结

1.https://leetcode.com/problems/subsets/description/这里要注意下次递归的起点是i而非posclass Solution {void subsetsAux(vector<vector<int>>& ans,vector<int>& vt,vector<int>& n...

2018-08-29 17:24:43 142

原创 单源最短路径算法

问题引入:给定一个图和图中一顶点root,如何获取该顶点到图中所有顶点的最短路径。通常有两种方法:DIjkstra算法和Bellman-Ford算法,先说第一种算法。(1)DIjkstra算法思想主要是维护两个集合,第一个集合是已经求的的最短路径中的顶点s1,第二个则是尚未求的最短路径的顶点s2。每次从s2中选择一个和root距离最短的顶点u,利用此顶点去更新s2中的所有顶点的距离。(...

2018-08-24 22:00:00 829

原创 深度优先遍历和宽度优先遍历问题

Pacific Atlantic Water Flow(https://leetcode.com/problems/pacific-atlantic-water-flow/description/)Sol1(BFS):设置两个visited数组记录两个大洋边界宽搜的结果,则两个visited都访问过的节点就是结果。class Solution {public: typede...

2018-08-12 21:39:41 403

原创 股票交易类问题总结

 股票交易类问题,要求在一定时间买入,然后卖出,以使利益最大化,通常采用动态规划求解。1.算法导论第三版投资挥发性公司即最大子数组问题(P39)首先采用分治法,假定要寻找子数组A[low...high]的最大子数组,利用分治将数组划分为规模尽量相等的子数组A[low...mid],A[mid+1...high]。则A[low...high]的任何连续子数组所处位置必定是以下三种情况之一...

2018-08-09 09:20:43 448

原创 #1141 : 二分·归并排序之逆序对

分析:按照官方提示,在归并排序的过程中统计。注意:(1)结果可能很大,用long long;(2)第二行输入数据从左到右等级依次递增。代码如下:#include <iostream>#include <vector>#include <algorithm>using namespace std;typedef long long ll;...

2018-08-02 20:13:06 135

原创 #1055 : 刷油漆题解

代码链接:https://hihocoder.com/problemset/problem/1055?sid=1345460分析:根据提示,定义f[t][m]表示“在以t为根的一棵树中,选出包含根节点t的m个连通的结点,能够获得的最高的评分”。很明显,经多动态规划后答案就是f[1][m]。假设节点t有cn个子节点,按照题目要求“将包含1号结点的一部分连通的结点进行涂漆(这里的连通指的是这一...

2018-07-28 21:12:40 234

原创 二叉树遍历方式总结

递归方式比较直观就不说了。树节点定义:struct TreeNode{ int val; TreeNode* left, *right; TreeNode(int _val):val(_val),left(nullptr),right(nullptr){}};前序遍历:list<int> preOrder(TreeNode* root){...

2018-07-20 21:23:43 118

原创 Recover Binary Search Tree

代码链接:https://leetcode.com/problems/recover-binary-search-tree/description/思路:找到两个需要交换的节点(first,second),将它们的值交换即可。根据二叉搜索树的特性,中序遍历序列是一个递增序列(a1<a2<a3<...<an)。(1)若ai>a(i+1)则ai即为第一个需要交换的节点;(...

2018-07-07 19:30:33 89

原创 国庆出游

代码链接:https://hihocoder.com/problemset/problem/1041 思路: (1)预处理

2017-10-06 16:37:58 1396

原创 二分图最大匹配

问题来源:腾讯SNG雏鹰计划要求做的mini项目,绪聊app中需要根据用户的性别、年龄、喜欢的tag等综合因素对其他用户打分,需要寻找一个最佳的方法使得用户整体满意度最大。 解决方案: (1)根据需求:对一个用户寻找候选用户时,如果性别不符合用户喜好直接淘汰。先进行第一级划分,根据用户对性别的偏好划分为两个集合:喜欢男生的集合X,喜欢女生的集合Y。 (2)贪心策略,即:对元素少的集合X中的每一

2017-08-06 17:36:23 358

原创 hihocoder图片排版

问题描述:http://hihocoder.com/problemset/problem/1365 思路来源:http://blog.csdn.net/lubovbyc/article/details/52348812 声明:并非完全原创,思路完全借鉴上述大神。只是大神毕竟大神,寥寥数语便解决了问题,理解起来很费劲,所以写此博客,解释下大神的思路。 这个问题类似于动态规划问题,思路如下: (

2017-08-06 17:23:12 285

原创 pandas中loc iloc ix的区别

pandas中loc iloc ix的区别 在pandas0.20.0及以上版本,ix已经丢弃,鼓励使用loc和iloc; 观察下面的代码:>>> s = pd.Series(np.nan, index=[23,34,61,14,0, 1, 2, 3])>>> s23 NaN34 NaN61 NaN14 NaN0 NaN1 NaN2 N

2017-06-17 11:27:13 1770

原创 1024. Palindromic Number (25)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

2016-12-18 21:10:23 168

原创 1025. PAT Ranking (25)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists wi

2016-12-18 17:28:06 221

原创 1001. A+B Format (20)

Calculate a + b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach input file contains one t

2016-12-18 17:26:35 178

原创 Roman to Integer(罗马数字转换成整数)

**Problem:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.** *构数规则:基本字符有7个:I,V,X,L,C,D,M,分别表示1,5,10,50,100,500,1000。 1、相同的数字连写,所表示的数等于这些数字相

2016-10-22 08:39:18 259

原创 有序等长数组求中位数问题

问题描述:Let X[1..n] and Y[1..n] be two arrays, each containing n numbers already in sorted order. Give an O(lgn)-time algorithm to find the median of all 2n elements in arrays X and Y.懒得写了,直接复制原问题,意思大概都知道

2016-10-14 10:33:42 365

原创 抽象基类构造函数初探

抽象基类构造函数可以定义在类外么? 显然可以#pragma once#include<string>using std::string;class Quote {public: Quote() = default; Quote(const string& s, double p); string isbn()const { return bookNo; }

2016-09-24 16:46:34 529

原创 最大堆k路归并

问题:设计一个时间复杂度为O(n*lgk)的算法,它能够将k个有序链表合并为一个有序表,这里n是所有输入链表包含的总的元素个数

2016-09-23 21:17:41 301

原创 C++primer 5th exercise section 12.1.6 答案

代码很长,直接给出解决方案://The definition of class StrBlob、StrBlobPtr、ConstStrBlobPtr#pragma once#include#include#include#include#include// class StrBlobclass StrBlobPtr;class ConstStrBlobP

2016-05-04 11:32:37 263

原创 The Primer of Classes

It took a long time for me to study classes.     The fundamental ideas behind classes are data abstraction and encapsulation. Data abstraction is the ability to define both data and function membe

2016-04-15 10:34:37 273

原创 液体粘稠性系数的测定数据处理程序

小可的第一篇博文哦,这是一个关于普物实验数据的程序,尽管已经很细心地去写了,由于对类还不熟,也就没敢用,质量有点差哦,可是普物实验数据太多太复杂了,先写一个小程序奉献给筒子们吧,最后,如有问题欢迎指正^_6下面奉上源代码: #include#includeusing namespace std;double ave(double a,double b,double c,doub

2013-10-01 08:44:37 1216

Python Machine Learning

高清

2017-05-24

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除