自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(628)
  • 资源 (4)
  • 收藏
  • 关注

原创 问题解决:‘djongo‘ isn‘t an available database backend.

在django中使用django连接mongodb时,修改settings.py为如下:DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'xxx', }}修改后报错:/Applications/PyCharm.app/Contents/helpers/pycharm/django...

2020-04-11 15:37:59 3413

原创 关于Scrapy ItemLoader、MapCompose、Compose、input_processor与output_processor的一些理解

本文以一个当当网图书出版社信息举例,说明Scrapy中,ItemLoader、MapCompose、Compose、input_processor与output_processor的一些使用事项。先给出spider与item的代码实例:spider:def parse_item(self, response): for r in response.css(".bang_list ...

2020-04-09 20:48:05 1312

原创 Scrapy设置User-Agent随机代理

User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本、CPU 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件等。一些网站常常通过判断 UA 来给不同的操作系统、不同的浏览器发送不同的页面,因此可能造成某些爬虫被网站禁止,但通过伪装 UA 可以绕过检测。常见的User-Agent形式如:Mozilla/5.0 (Maci...

2020-04-01 12:16:17 1050

原创 使用Turicreate三行代码构建推荐系统

Apple开源机器学习框架Turi Create简化了自定义机器学习模型的开发。可以轻易地实现图像识别、聚类分析与推荐系统等多种机器学习需求。本文介绍了使用Turicreate快速构建电影推荐系统的一个实例。记得当初我参加18年泰迪杯时,为了实现推荐系统竟手写了800行代码。但现在看来,利用TuriCreate,基于物品的协同过滤模型(item-based CF)可以在三行代码内轻易完成。...

2020-01-12 19:19:36 961

原创 Jupyter Notebook使用Anaconda虚拟环境

创建和使用虚拟环境的过程见:Anaconda虚拟环境第一步:安装ipykernel:法一:1.进入虚拟环境Windows:在Anaconda Prompt, 运行 activate myenvmacOS & Linux, 在Terminal, 运行 source activate myenv安装ipykernel:conda install ipykernel法二:...

2020-01-10 10:01:16 6576 2

原创 快速生成N*N的随机矩阵

实测单线程生成10000*10000的随机数矩阵只要2s核心思想在于将二维矩阵转化为一维数组进行操作编译:g++ -std=c++11 randomMaker.cpp -o randomMaker运行:./randomMaker <dimension>randomMaker.cpp:#include <cstdlib>#include <algorithm...

2019-10-17 10:28:45 3013

原创 PAT甲级 1045. Favorite Color Stripe (30)

Eva 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...

2019-05-23 22:18:40 312

原创 PAT甲级 1057. Stack (30) 【树状数组/线段树】

Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Po...

2019-05-23 18:49:38 533

原创 OpenMP并行实现枚举排序

程序通过生成随机数组,利用OpenMP实现并行化的枚举排序算法,并与串行算法进行了比较。#include <omp.h>#include <time.h>#include <string.h>#include <stdio.h>#define maxn 100000#define NUM_THREADS 20int n;int ...

2019-05-21 16:11:42 1313 1

原创 OpenMP 互斥锁函数

OpenMP API所提供的互斥函数可放在任意需要的位置。程序员必须自己保证在调用相应锁操作之后释放相应的锁,否则就可能造成多线程程序的死锁。下面为OpenMP API函数提供的互斥函数和可嵌套的互斥锁函数。void omp_init_lock(omp_lock*):初始化互斥器void omp_destroy_lock(omp_lock*):销毁互斥器void omp_set_lock(...

2019-05-21 16:08:43 2577

原创 OpenMP critical临界区

临界区用在可能产生数据访问竞争的地方,用法:#pragma omp critical (name) (name可省略)。保证每次只有一个线程进入。注意:critical语句不允许互相嵌套例:在一个并行域内的for任务分担域中,各个线程逐个进入到critical保护的区域内,比较当前元素的最大值得关系并可能进行最大值的更替,从而避免了数据竞争的情况。#include <stdio.h&g...

2019-05-21 16:07:36 2237

原创 OpenMP并行计算矩阵向量相乘

程序计算随机生成的矩阵与向量相乘函数f():单线程计算函数fp():多线程并行计算#include <stdio.h>#include <omp.h>#include <stdlib.h>#include <time.h>const int NUM_THREADS = 20;typedef long long ll;int m ...

2019-05-21 16:06:19 6314 2

原创 OpenMP编程

1. 执行模式概述:OpenMP是跨平台的多核多线程编程的一套指导性的编译处理方案(Compiler Directive),指导编译器将代码编译为多线程程序。Openmp的执行模型采用fork-join的形式,其中fork(派生)创建新线程或者唤醒已有线程;join即多线程的会合。[image:2DCC5666-87E6-475C-9A7B-A94C61A4D4C1-563-000023...

2019-05-21 15:57:37 2199

原创 PAT甲级 1134 Vertex Cover (25 分)

A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to tell if e...

2019-05-20 11:03:24 323

原创 PAT甲级 1135 Is It A Red-Black Tree (30 分) 【红黑树】

There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black.(2) The root is black.(3) Every le...

2019-05-19 21:22:09 552

原创 1136 A Delayed Palindrome (20 分) 【大数加法】

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​ ⋯a​1​​ a​0​​ with 0≤a​i​​ <10 for all i and a​k​​ >0. Then N is palindromic if and only if...

2019-05-19 18:19:46 513

原创 PAT甲级1137 Final Grading (25)

For a student taking the online course “Data Structures” on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from...

2019-05-19 17:32:23 424 1

原创 PAT 甲级 1138 Postorder Traversal (25 分)

Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal se...

2019-05-19 12:13:31 199

原创 使用unordered_set&lt;pair&lt;int,int&gt;&gt; unordered_map&lt;pair&lt;int,int&gt;, bool&gt;

本文介绍C++11特性下使用unordered_set<pair<int, int>>与unordered_map<pair<int, int>, bool>的方法,int换为其他数据类型方法一致。众所周知,基于红黑树(RB-Tree)的set与map是可以使用std::pair的,而unoredered_set与unordered_map的内部实...

2019-05-19 10:52:41 7589

原创 PAT 甲级 1139 First Contact (30 分)【模拟好题】

Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly i...

2019-05-19 09:42:35 852

原创 PAT甲级 1140 Look-and-say Sequence (20 分)

Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, …where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number....

2019-05-18 19:55:53 450

原创 PAT 甲级 1142 Maximal Clique (25 分)

A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adj...

2019-05-18 12:31:18 269

原创 PAT甲级 1143 Lowest Common Ancestor (30 分)【LCA】

The 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 t...

2019-05-18 11:32:15 297

原创 PAT甲级 1144 The Missing Number (20 分)

Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Specification:Each input file contains one test case. For each case, the first line gives...

2019-05-18 08:57:17 268

原创 PAT甲级 1145 Hashing - Average Search Time (25 分) 【哈希 二次探测法】

The 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 average sea...

2019-05-17 22:12:50 387

原创 PAT甲级 1146 Topological Order (25 分) 【拓扑排序】

This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test...

2019-05-17 21:18:35 505

原创 PAT甲级 1147 Heaps (30 分)

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...

2019-05-17 19:48:26 261

原创 PAT甲级 1148 Werewolf - Simple Version (20 分)

Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,player #1 said: “Player #2 is a werewolf.”;player #2 said: ...

2019-05-17 14:59:45 271

原创 PAT甲级 1149 Dangerous Goods Packaging (25 分)

When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂)...

2019-05-17 10:47:56 276

原创 PAT甲级 1150 Travelling Salesman Problem (25 分) 【哈密顿回路】

The “travelling salesman problem” asks the following question: “Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and retu...

2019-05-17 10:27:47 336

原创 PAT甲级 1151 LCA in a Binary Tree (30 分) 【LCA】

The 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.Given any two nodes in a binary tree, you are supposed to find their LCA.Inpu...

2019-05-16 19:21:35 294

原创 PAT甲级 1152 Google Recruitment (20 分)【字符串模拟】

In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit p...

2019-05-16 17:38:12 475

原创 PAT甲级 1153 Decode Registration Card of PAT 【字符串模拟】

A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic;the 2nd - 4th digits are the test site numb...

2019-05-16 15:55:04 290

原创 PAT甲级 1155 Heap Paths【堆 dfs】

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...

2019-05-16 10:46:58 249

原创 POJ 1845 Sumdiv【乘法逆元+费马小定理】

DescriptionConsider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).InputThe only line contains the two...

2019-05-10 21:29:23 228

原创 【算法竞赛进阶指南】NOIP2011/CH3601 计算系数 【组合计数 阶乘逆元 费马小定理】

题目描述给定一个多项式(ax+by)k(ax+by)^k(ax+by)k,请求出多项式展开后xnymx^ny^mxnym项的系数。输入格式共一行,包含 5 个整数,分别为 a,b,k,n,m,每两个整数之间用一个空格隔开。输出格式输出共 1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果。数据范围0≤n,m≤k≤1000,n+m=k,0≤a,b...

2019-05-10 20:51:01 328

原创 POJ 3696 The Luckiest Number 【欧拉函数+快速幂】

DescriptionChinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among...

2019-05-10 17:43:17 246

原创 FZU 1759 Super A^B mod C 【欧拉函数 降幂公式】

Problem DescriptionGiven A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).InputThere are multiply testcases. Each testcase, there is on...

2019-05-10 15:57:51 250

原创 POJ3090 Visible Lattice Points 【欧拉函数+欧式筛法】

在一个平面直角坐标系的第一象限内,如果一个点(x,y)与原点(0,0)的连线中没有通过其他任何点,则称该点在原点处是可见的。例如,点(4,2)就是不可见的,因为它与原点的连线会通过点(2,1)。部分可见点与原点的连线如下图所示:编写一个程序,计算给定整数N的情况下,满足0≤x,y≤N的可见点(x,y)的数量(可见点不包括原点)。输入格式第一行包含整数C,表示共有C组测试数据。每组测试...

2019-05-10 14:55:46 382

原创 【算法竞赛进阶指南】CH5401 没有上司的舞会 树形dp

Ural大学有N名职员,编号为1~N。他们的关系就像一棵以校长为根的树,父节点就是子节点的直接上司。每个职员有一个快乐指数,用整数 Hi 给出,其中 1≤i≤N。现在要召开一场周年庆宴会,不过,没有职员愿意和直接上司一起参会。在满足这个条件的前提下,主办方希望邀请一部分职员参会,使得所有参会职员的快乐指数总和最大,求这个最大值。输入格式第一行一个整数N。接下来N行,第 i 行表示 i...

2019-05-09 21:04:08 409

ACM校赛题解.pptx

ACM校赛

2019-10-26

python爬取淘宝商品信息

import requests from bs4 import BeautifulSoup import bs4 def getHTMLText(url): try: r = requests.get(url, timeout=30) r.raise_for_status() r.encoding = r.apparent_encoding return r.text except: return "" def fillUnivList(ulist, html): soup = BeautifulSoup(html, "html.parser") for a in soup.find('tbody').children: if isinstance(a, bs4.element.Tag): tds = a('td') ulist.append([tds[0].string, tds[1].string, tds[2].string, tds[3].string]) def printUnivList(ulist, num): print("{:^10}\t{:^6}\t{:^6}\t{:^16}".format("排名","学校名称","地区","总分")) for i in range(num): u=ulist[i] print("{:^10}\t{:^6}\t{:^6}\t{:^16}".format(u[0],u[1],u[2],u[3]))

2018-01-26

调用sklearn库的K-Means聚类分析实例

#class sklearn.cluster.KMeans(n_clusters=8, init=’k-means++’, n_init=10, max_iter=300, tol=0.0001, precompute_distances=’auto’, verbose=0, random_state=None, copy_x=True, n_jobs=1, algorithm=’auto’) #参数: #(1)对于K均值聚类,我们需要给定类别的个数n_cluster,默认值为8; #(2)max_iter为迭代的次数,这里设置最大迭代次数为300; #(3)n_init设为10意味着进行10次随机初始化,选择效果最好的一种来作为模型; #(4)init=’k-means++’ 会由程序自动寻找合适的n_clusters; #(5)tol:float形,默认值= 1e-4,与inertia结合来确定收敛条件; #(6)n_jobs:指定计算所用的进程数; #(7)verbose 参数设定打印求解过程的程度,值越大,细节打印越多; #(8)copy_x:布尔型,默认值=True。当我们precomputing distances时,将数据中心化会得到更准确的结果。如果把此参数值设为True,则原始数据不会被改变。如果是False,则会直接在原始数据上做修改并在函数返回值时将其还原。但是在计算过程中由于有对数据均值的加减运算,所以数据返回后,原始数据和计算前可能会有细小差别。 #属性: #(1)cluster_centers_:向量,[n_clusters, n_features] # Coordinates of cluster centers (每个簇中心的坐标??); #(2)Labels_:每个点的分类; #(3)inertia_:float,每个点到其簇的质心的距离之和。

2018-01-26

2019蓝桥杯.zip

2019年蓝桥杯B组省赛C/C++试题,包括PDF文件、A-J题全部试题的图片、数据等。试题解析可以参考:https://blog.csdn.net/zhaohaibo_/article/details/88783978

2019-11-12

空空如也

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

TA关注的人

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