自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(53)
  • 收藏
  • 关注

原创 Little Pony and Summer Sun Celebration CodeForces #453C 题解[C++]

题目来源http://codeforces.com/contest/453/problem/C题意理解Twilight Sparkle wanted to track the path of Nightmare Moon. Unfortunately, she didn’t know the exact path. What she knew is the parity of ...

2018-07-08 15:51:49 322

原创 Preparing Olympiad CodeForces #550B 题解[C++]

题目来源http://codeforces.com/problemset/problem/550/B题意理解You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest...

2018-07-07 17:48:03 349

原创 Anscombe's quartet

Part 1For each of the four datasets…Compute the mean and variance of both x and y Compute the correlation coefficient between x and y Compute the linear regression line: y=β0+β1x+ϵ (hint: use st...

2018-06-12 14:15:57 335

原创 Scipy库的一些应用

Exercise 10.1对于最小二乘法, 因为Scipy中对应的实现是基于假定: Data=m*(n+1)来的, 也就是说我们需要附加一列全为 1 的列到原始数据中. 这样一来, 我们就可以省略截距. 具体证明过程可以看这里: 正规方程.代码实现如下:"""Exercise 10.1: Least squaresGenerate matrix A 2 Rm×n ...

2018-06-02 14:56:52 780

原创 Jamie and Interesting Graph CodeForces #916C[题解]

题目来源http://codeforces.com/contest/916/problem/C题意理解Jamie has recently found undirected weighted graphs with the following properties very interesting:The graph is connected and contains ex...

2018-06-01 19:24:57 328

原创 Liebig's Barrels CodeForces #985C 题解[C++]

题目来源http://codeforces.com/contest/985/problem/C题意分析You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k...

2018-06-01 13:33:55 484

原创 Shortest Path of the King CodeForces #3A 题解[C++]

题目来源http://codeforces.com/contest/3/problem/A题意解析The king is left alone on the chessboard. In spite of this loneliness, he doesn’t lose heart, because he has business of national importance....

2018-05-30 10:47:27 383

原创 Two Buttons CodeForces #520B 题解[C++]

题目来源http://codeforces.com/contest/520/problem/B题目描述Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive...

2018-05-30 00:28:03 399

原创 Matplotlib绘制高斯核概率分布(Gaussian kernel density estimator)等实战

Exercise 11.1这个十分简单, plot霸王硬上弓即可."""Exercise 11.1: Plotting a functionPlot the functionf(x) = sin2(x − 2)e−x2over the interval [0; 2]. Add proper axis labels, a title, etc."""import mat...

2018-05-26 22:03:15 7382 1

原创 Numpy的一些矩阵运算实例

题目如下代码实现前三题的代码如下:import numpy as npfrom scipy.linalg import toeplitzfrom scipy.sparse.linalg import svds# Generate matrices A, with random Gaussian entries, B, a Toeplitz matrix, whe...

2018-05-22 23:29:41 996

原创 线性回归及Python实现实例

线性回归模型常常遇到这样的问题, 我们要进行线性回归的自变量 xxx 不是一个单独的值, 而是一个RnRnR^n 的向量. 这种情况即是多元线性回归.我们的目的就不再是寻找单独的值kkk和bbb来满足一次方程, 而是寻找到在RnRnR^n的向量www和标量bbb使得: y′=wTxi+by′=wTxi+by'=w^Tx_i+b 其中y′y′y'’即是回归方程的预测值. 那么, 要求...

2018-05-21 06:30:23 2784 3

原创 Best Time to Buy and Sell Stock Leetcode #121 题解[Python]

题目来源https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/题目描述Say you have an array for which the ith element is the price of a given stock on day i.If you were only pe...

2018-05-12 14:59:10 247

原创 Maximum Depth of Binary Tree Leetcode #104 题解[Python]

题目来源https://leetcode.com/problems/maximum-depth-of-binary-tree/description/题意分析Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path f...

2018-05-12 14:43:30 228

原创 Count Primes Leetcode #204 题解[Python]

题目来源https://leetcode.com/problems/count-primes/description/题目描述Count the number of prime numbers less than a non-negative number, n.Example: Input: 10 Output: 4 Explanation: Ther...

2018-05-12 14:35:35 379

原创 Number of Atoms Leetcode #726 题解[C++]

题目来源https://leetcode.com/problems/number-of-atoms/description/题意分析Given a chemical formula (given as a string), return the count of each atom.An atomic element always starts with an upperc...

2018-05-12 14:11:18 624

原创 Maximum Gap Leetcode #164 题解[Python]

题目来源https://leetcode.com/problems/maximum-gap/description/题意分析Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array ...

2018-05-12 13:21:18 832

原创 Sort Colors Leetcode #75 题解[C++]

题目来源https://leetcode.com/problems/sort-colors/description/题目描述Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, wit...

2018-05-12 12:57:17 334

原创 Search a 2D Matrix Leetcode #74 题解[Python]

题目来源https://leetcode.com/problems/search-a-2d-matrix/description/题目描述Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Int...

2018-05-12 12:37:40 280

原创 Insert Interval Leetcode #57 题解[Python]

题目来源https://leetcode.com/problems/insert-interval/description/题目描述Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume tha...

2018-05-12 11:21:45 1336

原创 Maximum Subarray Leetcode #53 题解[Python]

题目来源https://leetcode.com/problems/maximum-subarray/description/题目描述Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and re...

2018-05-12 11:06:25 798

原创 PCA降维方法及在AT&T人脸数据集的应用实例

本篇博文对AT&T剑桥大学实验室[1]的人脸数据集应用了主成分分析策略, 做了一些可视化处理.算法原理假设在RnRnR^n空间中有mmm个点, 我们希望对这些点进行有损压缩, 使数据的维度从RnRnR^n变为RlRlR^l, 其中严格的有l<nl<nlxi∈Rnxi∈Rnx^i\in R^n, 使得其被投影为ci∈Rlci∈Rlc^i\in R^l, 用函数...

2018-05-06 19:28:44 2848

原创 Partition to K Equal Sum Subsets Leetcode #698 题解[Python]

题目来源https://leetcode.com/problems/partition-to-k-equal-sum-subsets/description/题目描述Given an array of integers nums and a positive integer k, find whether it’s possible to divide this array...

2018-05-05 00:15:00 487

原创 Median of Two Sorted Arrays Leetcode #4 题解[C++]

题目来源https://leetcode.com/problems/median-of-two-sorted-arrays/description/题意解析There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arr...

2018-05-01 01:46:01 163

原创 Merge K Sorted List Leetcode #23 题解[C++]

题目来源https://leetcode.com/problems/merge-k-sorted-lists/description/题目描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example: Input:...

2018-05-01 00:22:42 236

原创 Kth Largest Element in an Array Leetcode #215 题解[C++]

题目来源https://leetcode.com/problems/kth-largest-element-in-an-array/description/题目理解ind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted or...

2018-04-30 20:50:49 280

原创 Sort List Leetcode #148 题解[C++]

题目来源https://leetcode.com/problems/sort-list/description/题目描述Sort a linked list in O(n log n) time using constant space complexity.Example 1: Input: 4->2->1->3 Output: 1-&...

2018-04-30 18:07:01 262

原创 Gas Station Leetcode #134 题解[C++]

题目来源https://leetcode.com/problems/gas-station/description/题目理解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 unlimit...

2018-04-30 14:39:50 267

原创 Jump Game Leetcode #55 题解[C++]

题目来源https://leetcode.com/problems/jump-game/description/题目描述Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array ...

2018-04-30 10:36:37 235 1

原创 Triangle Leetcode #120 题解[C++]

题目来源https://leetcode.com/problems/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, give...

2018-04-30 02:25:22 313

原创 House Robber Ⅱ Leetcode #213 题解[C++]

题目来源https://leetcode.com/problems/house-robber-ii/description/题目理解After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not ge...

2018-04-29 13:36:52 310

原创 House Robber Leetcode #198 题解[Python]

题目描述You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjace...

2018-04-29 10:11:13 161

原创 Longest Palindromic Substring Leetcode #5 题解[Python]

题目描述Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answ...

2018-04-27 18:37:09 165

原创 Search in the rotated array Leetcode #33 题解[Python]

题目描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. I...

2018-04-27 01:21:12 153

原创 Contain with most water Leetcode #11 题解[Python]

题目描述Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin...

2018-04-26 00:56:22 306

原创 Python入门与实践 Chapter 11 动手试一试

11-1 城市和国家 : 编写一个函数, 它接受两个形参: 一个城市名和一个国家名。 这个函数返回一个格式为City, Country 的字符串, 如Santiago, Chile 。 将 这个函数存储在一个名为city_functions.py的模块中。创建一个名为test_cities.py的程序, 对刚编写的函数进行测试(别忘了, 你需要导入模块unittest 以及要测试的函数) 。 编...

2018-04-15 14:35:28 263

原创 Python入门与实践 Chapter 10 动手试一试

10-8 猫和狗 : 创建两个文件cats.txt和dogs.txt, 在第一个文件中至少存储三只猫的名字, 在第二个文件中至少存储三条狗的名字。 编写一个程序, 尝试读取这些文件, 并将其内容打印到屏幕上。 将这些代码放在一个try-except 代码块中, 以便在文件不存在时捕获FileNotFound 错误, 并打印一条友好的消息。 将其中一个文件 移到另一个地方, 并确认except ...

2018-04-07 21:36:07 330

原创 Python入门与实践 Chapter 9 动手试一试

9-3 用户 : 创建一个名为User 的类, 其中包含属性first_name 和last_name , 还有用户简介通常会存储的其他几个属性。 在类User 中定义一个名 为describe_user() 的方法, 它打印用户信息摘要; 再定义一个名为greet_user() 的方法, 它向用户发出个性化的问候。 创建多个表示不同用户的实例, 并对每个实例都调用上述两个方法。9-5 尝...

2018-04-07 20:28:56 215

原创 Python入门与实践 Chapter 8 动手试一试

8-9 魔术师 : 创建一个包含魔术师名字的列表, 并将其传递给一个名为show_magicians() 的函数, 这个函数打印列表中每个魔术师的名字。 8-10 了不起的魔术师 : 在你为完成练习8-9而编写的程序中, 编写一个名为make_great() 的函数, 对魔术师列表进行修改, 在每个魔术师的名字中都加入字样“the Great”。 调用函数show_magicians() , ...

2018-03-30 01:36:45 613 3

原创 Python入门与实践 Chapter 7 动手试一试

7-5 电影票 : 有家电影院根据观众的年龄收取不同的票价: 不到3岁的观众免费; 3~12岁的观众为10美元; 超过12岁的观众为15美元。 请编写一个循环, 在其中询问用 户的年龄, 并指出其票价。 7-9 五香烟熏牛肉(pastrami) 卖完了 : 使用为完成练习7-8而创建的列表sandwich_orders , 并确保’pastrami’ 在其中至少出现了三次。 在程序开头附近添加...

2018-03-28 21:29:50 645

原创 Python入门与实践 Chapter 6 动手试一试

6-5 河流 : 创建一个字典, 在其中存储三条大河流及其流经的国家。 其中一个键—值对可能是’nile’: ‘egypt’ 。 使用循环为每条河流打印一条消息, 如“The Nile runs through Egypt.”。 使用循环将该字典中每条河流的名字都打印出来。 使用循环将该字典包含的每个国家的名字都打印出来。 6-12 扩展 : 本章的示例足够复杂, 可以以很多方式进行扩展了...

2018-03-25 16:51:14 391

空空如也

空空如也

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

TA关注的人

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