码迷,mamicode.com
首页 >  
搜索关键字:algorithm    ( 11758个结果)
Hdu 4916 Count on the path
题意:给定一棵树顶点标号为连续的1~n,每次在线询问不在a-b路径上标号最小的点 这题想了好久,假设1为首先如果a-b不过根节点1,答案一定是1。否则我们用fa[i]表示i节点的父亲,belong[i]表示i节点祖先是belong[i],且belong[i]是根节点儿子。这样我们可以预处理出ans[i]表示在belong[i]这颗子树中除去i到根节点的路径中最小的值。统计答案即可。 讨论时需注...
分类:其他好文   时间:2014-08-06 19:08:52    阅读次数:248
RMQ算法分析
RMQ算法,是一个快速求区间最值的离线算法,预处理时间复杂度O(n*log(n)),查询O(1),所以是一个很快速的算法,当然这个问题用线段树同样能够解决。 问题:给出n个数ai,让你快速查询某个区间的的最值。 算法分类:DP+位运算 算法分析:这个算法就是基于DP和位运算符,我们用dp【i】【j】表示从第 i 位开始,到第 i + 2^j 位的最大值或者最小值。 ...
分类:其他好文   时间:2014-08-06 18:58:52    阅读次数:222
Some thoughts..
I think it is natural for an algorithm rookie that when facing a challenging problem, a rookie may fall into her\his algorithm dictionary - she focuse...
分类:其他好文   时间:2014-08-06 14:36:21    阅读次数:232
The Hungarian algorithm Template
The Hungarian algorithm withThe adjacency matrix:计算最大匹配问题int n1, n2, m, ans;int res[MAXN];bool vis[MAXN], map[MAXN][MAXN];void init(){ int t1, t2; ...
分类:其他好文   时间:2014-08-06 14:18:31    阅读次数:208
hdu 1113 Word Amalgamation (map)
# include # include # include # include # include using namespace std; int main() { string s,t; int flag; mapq; while(cin>>s&&s!="XXXXXX") { t=s; sort(s.begin(),s.end()); q[t]=s; } w...
分类:其他好文   时间:2014-08-06 11:56:21    阅读次数:184
hdu 1236
排名 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15469    Accepted Submission(s): 5606 Problem Description 今天的上机考试虽然有实时的Ranklist,但上...
分类:其他好文   时间:2014-08-06 11:53:21    阅读次数:178
poj2299--归并排序求逆序数
/** \brief poj2299 * * \param date 2014/8/5 * \param state AC * \return memory 4640K time 3250ms * */ #include #include #include #include using namespace std; const int MAXN=500000; int Ar...
分类:其他好文   时间:2014-08-05 22:48:40    阅读次数:313
POJ3735 Training little cats DP,矩阵快速幂,稀疏矩阵优化
题目大意是,n只猫,有k个动作让它们去完成,并且重复m次,动作主要有三类gi,ei,s i j,分别代表第i只猫获得一个花生,第i只猫吃掉它自己所有的花生,第i只和第j只猫交换彼此的花生。k,n不超过100,m不超过1000,000,000,计算出最后每只猫还剩下多少个花生。         我们假设一个n维向量P,每个分量的值代表这n只猫所拥有的花生数,那么对于gi操作其实就是在第i维分量上加...
分类:其他好文   时间:2014-08-05 22:44:10    阅读次数:333
Leetcode :: Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without u...
分类:其他好文   时间:2014-08-05 22:35:00    阅读次数:277
poj1753--模拟
/** \brief poj 1573 * * \param date 2014/8/5 * \param state * \return memory 744k time 0ms * */ #include #include #include #include using namespace std; const int MAXN=11; int Map[MAXN][M...
分类:其他好文   时间:2014-08-05 19:31:40    阅读次数:187
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!