自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

思维迷宫

那是所有天才的通病

  • 博客(245)
  • 收藏
  • 关注

原创 决策树(Decision Tree)

决策树引导通俗来说,决策树分类的思想类似于找对象。现想象一个女孩的母亲要给这个女孩介绍男朋友,于是有了下面的对话:         女儿:多大年纪了?      母亲:26。      女儿:长的帅不帅?      母亲:挺帅的。      女儿:收入高不?      母亲:不算很高,中等情况。      女儿:是公务员不

2016-01-25 17:48:27 1056

翻译 Matplotlib tutorial(4)

Quick referencesHere is a set of tables that show main properties and styles.Line propertiesPropertyDescriptionAppearancealpha (or a)alpha transparency on

2016-01-25 14:35:24 854

翻译 Matplotlib tutorial(3)

Other types of plotsRegular PlotsStarting from the code below, try to reproduce the graphic on the right taking care of filled areas:import numpy as npimport matplotlib.pyplot as pltn = 256

2016-01-25 12:47:49 719

翻译 Matplotib tutorial(2)

Figures, Subplots, Axes and TicksSo far we have used implicit figure and axes creation. This is handy for fast plots. We can have more control over the display using figure, subplot, and axes expl

2016-01-23 17:44:04 778

转载 Numpy之random模块

简单的随机数据rand(d0, d1, ..., dn)随机值>>> np.random.rand(3,2)array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]])

2016-01-23 16:21:24 15665

翻译 Matplotlib tutorial(1)

Introductionmatplotlib is probably the single most used Python package for 2D-graphics. It provides both a very quick way to visualize data from Python and publication-quality figures in many form

2016-01-23 11:37:24 754

原创 kNN算法改进约会网站的配对效果

#coding = utf-8from numpy import *import operatorimport matplotlibimport matplotlib.pyplot as pltdef createDataset(): group = array([[1.0, 1.1], [1.0, 1.0], [0, 0], [0, 0.1]]) #生成一个数组 labels =

2016-01-15 15:59:53 998

原创 hdu 5371 Hotaru's problem

#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;const int M = (1 << 17);const int mod = 1e9 + 7;int n;vecto

2015-08-13 13:51:32 607

原创 Manacher算法(来自戴神的博客)

Manacher算法Manacher算法是查找一个字符串的最长回文子串的线性算法。在介绍算法之前,首先介绍一下什么是回文串,所谓回文串,简单来说就是正着读和反着读都是一样的字符串,比如abba,noon等等,一个字符串的最长回文子串即为这个字符串的子串中,是回文串的最长的那个。计算字符串的最长回文字串最简单的算法就是枚举该字符串的每一个子串,并且判断这个子串是否为回文串,这个算法的时间

2015-08-13 09:10:00 516

原创 树的重心

树的重心定义1.找到一个点 其所有的子树中最大的子树节点数最少 那么这个点就是这棵树的重心删去重心后 生成的多棵树尽可能平衡.2.以这个点为根,那么所有的子树(不算整个树自身)的大小都不超过整个树大小的一半。树的重心性质1.树中所有点到某个点的距离和中,到重心的距离和是最小的;如果有两个重心,那么他们的距离和一样。2.把两个树通过一条边相连得到一个新的树,那么新的树的重

2015-07-31 10:29:49 503

原创 hdu 2824 The Euler function

/*Euler's totient function 欧拉函数1.phi(x) = x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…(1-1/pn)(p1,p2...均为质因子)2.phi(i * p) = phi(i) * p, for (i mod p) = 03.phi(i * p) = phi(i) * (p-1), for (i mod p) ≠0,

2015-07-24 13:43:10 637

原创 D D - Om Nom and Necklace

官方题解(讲的非常详细)This task is to determine whether a string is in the form of ABABA... ABA for each prefixes of a given string SFor a prefix P, let's split it into some blocks, just like P = SS

2015-04-09 10:13:25 607

原创 hdu 3938 Portal

题意描述简单的讲就是,给你一张无向图,求有多少条路径使得路径上的花费小于L,这里路径上的花费是这样规定的,a、b两点之间的多条路径中的最长的边最小值!题目分析因为考虑到数据的大小所以需采用离线算法先计算出结果后在统一输出结果。这里首先要从a到b的所有路径中筛选出这样一条路径(路径中的最长边是所有路径中最小),那么这就需要采用最小生成树kruskal的思想,那么任意两个集合A,B之间可以

2015-04-07 22:24:23 548

原创 hdu 1598 find the most comfortable road

题意给出n个点m条边以及边的权值,求出点a到点b的一条路,这条路上所有边的最大值-最小值的值最小。这个题有两种做法:1.二分+最短路:枚举差值和最小值。2.并查集+Kruscal:排序后,枚举每一条边。AC代码(第二种做法)#include #include #include #include using namespace std;const int INF

2015-04-06 22:14:22 461

原创 hdu 3371 Connect the Cities

Prim求解最小生成树AC代码:#include #include #include #include #include using namespace std;const int MAX = 510;int G[MAX][MAX],ans;int good[110],dis[MAX],vis[MAX];int n, m, k;void init(){ for(

2015-04-05 17:10:06 353

原创 hdu 1272 小希的迷宫

判断是不是连通且无环的无向图:1.只能有一个根结点2.同一条边上的点父亲不能相同AC代码:#include #include #include #include using namespace std;const int MAX = 100010;bool vis[MAX];int father[MAX];void init(){ for(int i=0;

2015-04-05 10:53:40 376

原创 poj 3734 Blocks

第一道矩阵加速dp 加油哦 ^ ^

2015-04-05 10:03:25 392

原创 二分查找

2015-04-01 16:08:26 411

原创 poj 2182 Lost Cows

/*分析:由给定的数据我们从后往前进行求解s[n-1],s[n-2]...s[0] 当我们求解s[k]的时候,由于s[k+1]...s[n-1]已求到,所以只要确定了s[k] 就能确定s[k+1]~s[n-1]中比s[k]小的个数num,从而k-1-num就是s[k]前面比s[k]小的个数 如果s[k]-1-num == a[k](既输入的值),则该点可以是s[k],而如何确定s[k]呢?在

2015-04-01 15:56:41 426

原创 61E Enemy is weak

题意:有n个数a1, a2, ..., an,问i aj > ak的三角对有多少对(3 对于一个位置j,其左边有L[j]个比aj大的数,其右边有R[j]个比aj小的数,那么,ai可从L[j]个数中取,ak可从R[j]个数中取,此时可组成L[j] * R[j]个三角对,枚举j的位置,求和。由于数据量不小,2层for以O(n^2)找L与R已超过题目所允许的时间,这里恰恰可用树状数组来求得R,

2015-03-31 21:11:38 471

原创 hdu 4791 Alice's Print Service

我们发现先打印的时候如果不是需要多少打印多少,那么最优解一定是打印一个分界点那么多份,因为少打一份不合算,多打一份是浪费。这就很容易解决了,首先由于没有更新,只有询问,我们可以离线操作。首先统一预处理,用v[ i ]记录,打印s[ i ]这么多份时,最少花费多少钱。然后二分找到第一个大于等于需要打印的份数的标号,算出本来需要多少钱,和v[pos]取一个小,就是答案。最坑的是G++会TLE,C++才

2015-03-29 21:33:25 423

原创 poj 2762 Going from u to v or from v to u?

求有向图的弱连通分量。将有向图的所有的有向边替换为无向边,所得到的图称为原图的基图。如果一个有向图的基图是连通图,则有向图是弱连通图。如果有向图中,对于任意节点v1和v2,至少存在从v1到v2和从v2到v1的路径中的一条,则原图为单向连通图。即设G=是有向图,如果u->v意味着图G至多包含一条从u到v的简单路径,则图G为单连通图。强连通图、连通图、单向连通图三者之间的关系是,强连通图必然是单向连通

2015-03-16 22:32:57 472

原创 poj 2186 Popular Cows

求解图中任一点都能到达的点的个数(除自身外),强连通缩点后找出度为零的点,如果大于1个那么不存在符合条件的点。注意当图中只有一个SCC时输出n。 #include #include #include #include #include using namespace std; const int N = 10010; const int M = 50010; stac

2015-03-15 20:31:11 324

原创 poj 2553 The Bottom of a Graph

这个题的题意真是醉了 一个点是sink不是说他和任一点互相可达,而是如果他能到达一个点的情况下,那个点必须能够到达他 = =。这样的话就是强连通缩点之后,出度为零的点及其强连通分量中的所有点都是sink。#include #include #include #include #include using namespace std;const int N = 5010;con

2015-03-12 21:46:41 413

原创 hdu 2767 Proving Equivalences

这道题是问最少添加几条边使得整个图强连通。首先,我们知道强连通是一个等价的关系,那么我们可以将强连通分量缩成一个点,即这个强连通分量的编号,这个过程称为强连通缩点。缩点后图变成一个DAG(有向无环),只需统计出度和入度为0的点各有多少,然后取大。这很好理解,因为我们添加边是从一个出度为0的点连到入度为0的点,这样就可以使整个图强连通。具体实现用的是Tarjan的算法= =。#include

2015-03-11 16:24:20 437

原创 hdu 3849 By Recognizing These Guys, We Find Social Networks Useful

判断无向图的割点和桥的模板题,但是这个题要求按照输入的顺序输出边,因此需要把边保存以下,挺麻烦的其实,= =。#include #include #include #include #include #include using namespace std;const int MAX = 10010;typedef pair Pii;vector vt[MAX];

2015-03-10 09:12:45 375

原创 Two Buttons

求解由n到m只通过-1或*2最少需要多少步,典型动态规划问题,采用记忆化搜索。#include #include #include #include using namespace std; const int INF = 0x3f3f3f3f; int n,m;int dp[20010],vis[20010];int dfs(int u){ if(

2015-03-08 19:17:32 446

原创 CF #294

这次比赛的题目总体来讲比较水 因为我都做出了4个题 = =。A B C题这三个题没什么可说的太简单了= =。D题利用前缀和的思想,先预处理所有的前缀和,然后看开头字母相同的有没有前缀和相同的 有就是一个答案。需要注意 题目中会出现long long作下标的情况,因此要使用mapE题这是一个LCA的应用,由于所求涉及到割级祖先,使用在线倍增算法求解。#pr

2015-03-05 13:09:00 501

原创 poj 1470 Closest Common Ancestors

由于这个题很蛋疼 会有很详细的注释#pragma comment (linker, "/STACK:1024000000, 1024000000")#include #include #include #include #include using namespace std;const int N = 1010;const int MAX = 1000010;int

2015-03-04 21:51:03 302

原创 poj 1330 Nearest Common Ancestors

深搜果然学的像屎一样= =。#pragma comment (linker, "/STACK:1024000000, 1024000000")#include #include #include #include #include using namespace std;const int MAX = 10010;bool flag;int from,to,n;boo

2015-03-03 21:50:59 323

原创 hdu 2874 Connections between cities

离线算法求解最近公共祖先,第一次见卡内存这么紧的题= =。#pragma comment (linker, "/STACK:1024000000, 1024000000")#include #include #include #include #include using namespace std;const int N = 10010;const int MAX =

2015-03-03 20:52:45 272

原创 poj 1986 Distance Queries

也是求解LCA的模板题,最近才接触的,使用离线算法做的。#pragma comment (linker, "/STACK:1024000000, 1024000000")#include #include #include #include #include using namespace std;const int MAX = 100010;typedef pair

2015-03-03 09:11:39 408

原创 hdu 2586 How far away ?

lca问题,使用倍增算法求解。#pragma comment (linker, "/STACK:1024000000, 1024000000")#include #include #include #include #include using namespace std;const int MAX = 40010;struct edge{ int v, w, next;

2015-03-02 21:58:18 339

原创 poj 1144 Network

无向图的割顶定义割点:对于无向图G,如果删除某个点u后,连通分量数目增加,u就是图的割点。对于连通图,割点就是删除之后使图不再连通的点。时间戳:记录结点访问顺序的变量。树边:dfs森林中的边。反向边:第一次处理从后代指向祖先的边。是割顶的条件(连通图)1.树根:子结点数目>=22.非树根u:u存在一个子结点v,使得v及其所有后代都没有反向边连回u的祖先(连回u不算)

2015-02-22 10:49:31 405

原创 Uva 11624 Fire!

分析如果没有火,那么本题是一个标准的迷宫问题,可以用BFS解决。加上了火,难度增加没多少,由于起火便不会消失,我们可以预处理每个格子起火的时间,在BFS扩展结点时加一个判断,当到达的新结点没有着火时才加入队列。预处理实际上是一个最短路。代码#include #include #include #include #include using namespace std;c

2015-02-20 13:13:27 496

原创 poj 1226 Substrings

最长公共子串(后缀数组解法)仅正序poj 2774 long long message将字符串用不同的分隔符连接起来,求后缀数组和height数组即可,具体需要好好理解sa和height数组的含义。正序逆序均可poj 1226 Substrings将字符串用分隔符与自己的逆序连接后,将所有串连接在一起,然后与正序相同的求法。第二种情况的代码#include #in

2015-02-18 11:29:29 410

原创 poj 3294 Life Forms

题意输入n个DNA序列,你的任务是求出一个长度最大的字符串,使得超过一半的DNA序列中连续出现。如果有多解,按照字典序从小到大输出所有解。解法这是一道经典的题目,解法有很多。首先用不同的分隔字符把所有输入的字符串连接在一起。求这个新串的后缀数组和height数组,然后二分答案,每次只需要判断是否有一个长度为p的串在超过一半的串中连续出现。方法是把height分为若干段,每当height

2015-02-17 12:52:06 443

原创 poj 3261 Milk Patterns

求解单串的最长可重叠子串,二分+离散化+后缀数组

2015-02-17 10:49:32 337

原创 poj 1743 Musical Theme

题意:求一个字符串的不可重叠最长重复子串。题解:后缀数组经典题目。要先把串转换一下,根据题目的性质,应该把输入得到的串前后相减得到方便求解的新的串 —— 设其为s ,再求该串 s 中最长的不重叠重复子串。由于不能重叠,导致height 数组的最大值不一定是解,因为相邻两串可能会重叠。 此题用后缀数组也有两种解法, 1 :二分枚举答案, 2 :用栈线性扫描,主要说做法 1

2015-02-16 14:49:20 322

原创 poj 2774 Long Long Message

本题是求解最长公共子串,解法有两种,第一种是二分+ 哈希,第二种是后缀数组。下面介绍后缀数组的解法。将两个字符串用分隔符28连接起来,末尾补0,那么只需要求出这个字符串的后缀数组和height数组,找到起点分别在两个字符串的最大的height值即答案。AC代码:#include #include using namespace std;const int N = 2000

2015-02-16 13:27:38 405

空空如也

空空如也

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

TA关注的人

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