Fork me on GitHub
上一页 1 ··· 5 6 7 8 9 10 下一页
摘要: Dijkstra算法:解决带非负权重图的单元最短路径问题。时间复杂度为O(V*V+E)算法精髓:维持一组节点集合S,从源节点到该集合中的点的最短路径已被找到,算法重复从剩余的节点集V-S中选择最短路径估计最小的节点u,对u的所有连边进行松弛操作。即对j=1~n,dis[j] = min(dis[j]... 阅读全文
posted @ 2014-03-26 14:25 whatbeg 阅读(771) 评论(0) 推荐(0) 编辑
摘要: 题意很好懂,但是不好下手。这里可以把每个点编个号(1-25),看做一个点,然后能够到达即为其两个点的编号之间有边,形成一幅图,然后求最短路的问题。并且pre数组记录前驱节点,print_path()方法可用算法导论上的。代码:#include #include #include #include #... 阅读全文
posted @ 2014-03-22 15:44 whatbeg 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 这题其实很简单,每个人肯定都往上走,才能保证尽快赢,所以无非是看谁离根节点近,即深度小。。用并查集中的findset思想,不断找父节点一直到根节点来找深度就可以了。代码:#include #include #include #include #include using namespace std;#define N 100007int fa[N],n,cnt;void init(){ for(int i=1;i<=n;i++) fa[i] = i;}void findset(int x){ if(x != fa[x]) { findset(fa[... 阅读全文
posted @ 2014-03-19 09:50 whatbeg 阅读(250) 评论(0) 推荐(0) 编辑
摘要: class "note" 源码你仔细读完这篇文章,可能感觉不知所云,如果在这个纷杂乱世的世界,你能深入内心的对话自己,也许你可以能找到与我共鸣的地方,希望这篇文章可以帮到你。效果图: 阅读全文
posted @ 2014-03-17 13:31 whatbeg 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 这题昨天晚上花了我1个小时50多分钟来搞,都没有搞定。。后来看别人代码,直接暴力枚举第一个数的值来做。。最多1000*1000的复杂度。当时怎么就没想到呢?还有为啥我的方法不对呢。。暴力方法代码:#include #include #include #include #include #define... 阅读全文
posted @ 2014-03-17 13:12 whatbeg 阅读(233) 评论(0) 推荐(0) 编辑
摘要: Dijkstra模板题,也可以用Floyd算法。关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的。写法1:#include #include #include #include #include #define Mod 1000000007using namespace std;#... 阅读全文
posted @ 2014-03-16 22:47 whatbeg 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 这题的坑点在POJ输出double不能用%.lf而要用%.f。。。真是神坑。题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值。算法:Dijkstra题目每次选择权值最小的边进行延伸访问,最坏情况下每条路径都要访问,复杂度O(n^2)代码:#include #include #includ... 阅读全文
posted @ 2014-03-16 22:35 whatbeg 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 文章译自:http://www.techtimetea.com/5-making-mobile-application/1.开发这个APP的目的是什么?2.我应该做开发什么类型的APP?3.开发项目中需要哪些工具?4.先设计还是先敲代码?5.免费还是付费?1.开发这个APP的目的是什么?在应用市场上有成千上万的移动应用,所以只有做一个市场上没有的应用才会给你带来下载量。山寨应用通常只可能存活一段时间,所以,你的应用的排他性会保证你的应用的成功,尝试和解决一个现今至今为止没有被任何一个开发者解决的问题。如果你在做一个健康或者健身类的APP,你可以寻找别的这类APP,看哪些地方能够成为你能提供给用 阅读全文
posted @ 2014-03-12 18:38 whatbeg 阅读(368) 评论(0) 推荐(0) 编辑
摘要: 这题做的我好苦啊,编码调试整整搞了一个多小时,而且调到天昏地暗才调出来。。回归正题,这题是一道本人做过的比较烦,比较无聊的题之一。题意是一个人,在m个影星里有k个喜欢的影星,然后给出n场电影,每场电影给出演出的人的编号,0表示不确定,根据这些人的编号判断是否一定是最喜欢的电影(喜欢的影星最多的电影),或者一定不会是最喜欢的电影,或者是不确定。做法是算出每场电影最少有多少个喜欢的影星和最多有多少个喜欢的影星,并且得出在所有电影中最少有多少个喜欢的影星和最多有多少个喜欢的影星。如果分别用MIN和MAX来表示,则有三种情况:1.如果这场电影的MIN不小于任意一场电影的MAX,则这场电影必为最喜欢的电 阅读全文
posted @ 2014-03-12 18:05 whatbeg 阅读(563) 评论(0) 推荐(0) 编辑
摘要: 比赛链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=41856#overviewA.多种解法。可以dfs倒序染色,如mathlover神的代码:#include#includeusing namespace std;struct no... 阅读全文
posted @ 2014-03-09 19:35 whatbeg 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 搜索是ACM竞赛中的常见算法,本文的主要内容就是分析它的 特点,以及在实际问题中如何合理的选择搜索方法,提高效率。文章的第一部分首先分析了各种基本的搜索及其各自的特点。第二部分在基本搜索方法的基础上提出 一些更高级的搜索,提高搜索的效率。第三部分将搜索和动态规划结合,高效地解决实际问题,体现搜索的广泛应用性。第四部分总结全文。文章在分析各种搜索的同时,分析了我们在解题中应该怎样合理利用它,理论结合实际,对我们的解题实践有一定的指导意义。【 Abstract 】 Search is a algorithm which is often seen in ACM/ICPC .The main ide 阅读全文
posted @ 2014-03-06 21:10 whatbeg 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 简单搜索,我这里用的是dfs,由于棋盘只有8x8这么大,于是想到dfs应该可以过,后来由于边界的问题,TLE了,改了边界才AC。这道题的收获就是知道了有些时候dfs没有特定的边界的时候要自己设置一个合适的边界。这题推导可知,任意两点之间马踩6步之内一定能够到达,6步之内还未搜到说明绝对不是最优结果,果断退出。所以这里的res开始时最小设定为6即可,随着设的res的增大,运行时间越来越多,因为深搜可以有很多的分支,不采取较小的边界的话,可能会浪费很多时间在无用的搜索上,所以需要如此剪枝。反复提交验证发现,res设不同值的运行时间如下:res = 6 102msres = 10 222msres. 阅读全文
posted @ 2014-03-05 17:13 whatbeg 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 一段区间的最值问题,用线段树或RMQ皆可。两种代码都贴上:又是空间换时间。。RMQ 解法:(8168KB 1625ms)#include #include #include #include #include #include using namespace std;#define N 50003i... 阅读全文
posted @ 2014-03-05 14:56 whatbeg 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 采用优先队列做BFS搜索,d[][]数组记录当前点到源点的距离,每次出队时选此时eng最小的出队,能保证最先到达的是eng最小的。而且后来用普通队列试了一下,超时。。所以,能用优先队列的,就要用优先队列。代码:#include #include #include #include #include #include using namespace std;#define N 1003struct node{ int x,y; int eng; bool operator a.eng; }};char ss[N][N];int dis[N][N];int n,m,res;... 阅读全文
posted @ 2014-03-05 14:50 whatbeg 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 大白书上的例题,具体讲解见大白书,最好用用一个Log数组直接求k,这样就是纯O(1)了#include #include #include #include #include using namespace std;#define N 100003int a[N],num[N],le[N],ri[N... 阅读全文
posted @ 2014-03-04 12:36 whatbeg 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 优先队列。做法:维护两个优先队列:quesell 和 quebuy, 一个是小值优先,一个是大值优先。每次push的时候,都取各自的Top元素,比较价格,如果卖的比卖的出价低,则成交,各自的要买和要卖的股票数量减少能够减少的最大值,此时的DP(DealPrice)被记录下来。具体见代码:#include #include #include #include #include #include #include using namespace std;#define N 100003struct SELL{ int price,num; bool operator a.price; ... 阅读全文
posted @ 2014-03-01 10:28 whatbeg 阅读(502) 评论(0) 推荐(0) 编辑
摘要: 一直向前搜。。做法有点像模拟。但是要用到出队入队,有点像搜索。代码:#include #include #include #include #include #include using namespace std;#define N 100003struct node{ int p,d; bool operator a.d; return p>a.p; }}stone[N];int maxdis;priority_queue que;void GO(){ node now,next; int OE = 1; while(!que.empty(... 阅读全文
posted @ 2014-02-28 22:25 whatbeg 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 优先队列。。刚开始用蠢办法,经过一个vector容器中转,这么一来一回这么多趟,肯定超时啊。超时代码如下:#include #include #include #include #include #include #include #include #include #include #include using namespace std;#define N 30003priority_queue,greater > que;int A[N];vector tmp;int main(){ int m,n,i,j,th,u,k,h; while(scanf("%d%d" 阅读全文
posted @ 2014-02-28 21:56 whatbeg 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 好题。这题可以有三种解法:1.Dijkstra 2.优先队列 3.并查集我这里是优先队列的实现,以后有时间再用另两种方法做做。。方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索。代码:#include #include #include #include #include #include #include #include #include #include #include using namespace std;#define N 100007struct node{ int ind,wt; bool operator mp;priority_queue qu... 阅读全文
posted @ 2014-02-28 10:33 whatbeg 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 维护一个单调栈,保持从大到小的顺序,每次加入一个元素都将其推到尽可能栈底,知道碰到一个比他大的,然后res+=tail,说明这个cow的头可以被前面tail个cow看到。如果中间出现一个超级高的,自然会推到栈底,即此元素以前的cow看不到此元素后面cow的头,即res不会加此元素前面的个数,说明是正确的。注意要用long long 或者 __int64类型。 刚开始看着80000不大的样子,其实最大情况下res有 1+2+....+80000 = 3200040000,超过int范围。以后还是验证一下,或者看到这种比较大的数还是优先用long long 或者 __int64类型吧。代码:#in 阅读全文
posted @ 2014-02-26 14:37 whatbeg 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 做法:维护一个单调递减序列,只需输出序列中的第一个元素即可。对于命令我们可以进行不同的处理:如果是Q命令,则判断当前队列中是否仍有元素,如果没有则输出-1,如果有则直接输出队首。如果是G命令,则对last加1,之后对于队列中所有超出范围的前端元素进行出队操作。(该元素在原序列中的位置>=last)如果是C命令,则将该元素加入队列中,并和队尾元素比较,维护队列的单调性。这里考虑一个问题,当前元素加如后对队尾元素为什么可以毫无保留的删去呢?因为当前元素面试时间一定比队尾元素晚,所以如果当前元素比队尾元素大,则在当前元素被删去之前,删去队尾元素不影响最大值。代码:#include #inclu 阅读全文
posted @ 2014-02-26 09:20 whatbeg 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 重新刷这个经典题,感觉跟以前不一样了,变得更加容易理解了,不讲解了,看代码。注意:要用C++提交,用G++会超时。。代码:#include #include #include using namespace std;#define N 1000007int a[N],mp[N],head,tail,n,k;inline void pushup(int i){ while(tail > head && a[i] head && a[i] > a[mp[tail-1]]) tail--; mp[tail++] = i;}void solve(int cm 阅读全文
posted @ 2014-02-26 09:14 whatbeg 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 解法:因为至多20行,所以至多建20棵线段树,每行建一个。具体实现如下,有些复杂,慢慢看吧。#include #include #include #include #include using namespace std;#define N 1000010struct node{ int mi... 阅读全文
posted @ 2014-02-22 23:01 whatbeg 阅读(373) 评论(0) 推荐(0) 编辑
摘要: 1.POJ 3450 Coporate Identity这两题的解法都是枚举子串,然后匹配,像这种题目以后可以不用KMP来做,直接字符串自带的strstr函数搞定,如果字符串未出现,该函数返回NULL。下面贴出其比较。代码:(KMP版)(1360ms 888KB)#include #include #include #include #include using namespace std;#define N 4007char ans[203],str[203];char ss[N][203],tt[203];int next[203];void getnext(char *ss){ i... 阅读全文
posted @ 2014-02-22 14:26 whatbeg 阅读(311) 评论(0) 推荐(0) 编辑
摘要: A. Codeforces 92A Chips签到题。。#include #include #include #include #include using namespace std;#define N 10007int a[55];int main(){ int n,m,i; whi... 阅读全文
posted @ 2014-02-20 13:51 whatbeg 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 1.HDU 1711 Number Sequence代码:#include #include #include #include #include using namespace std;#define N 10007int a[1000007],b[N],next[N];int n,m;void getnext(){ next[0] = -1; int i = 0,j = -1; while(i#include #include #include #include using namespace std;#define N 10007int a[1000007],b[N],... 阅读全文
posted @ 2014-02-19 15:00 whatbeg 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 字典树较简单题,无需维护标记,注意细节即可。代码:#include #include #include using namespace std;#define N 100027struct node{ node *next[2];}*root;char ss[10][13];node *create(){ node *p; p = (node *)malloc(sizeof(node)); for(int i=0;inext[i] = NULL; return p;}void release(node *p){ for(int i=0;inext[i] !=... 阅读全文
posted @ 2014-02-12 16:33 whatbeg 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 较简单字典树,每输入一对字符串,前一个放在字典(数组)中,后一个插入字典树中,并将其最终的flag赋为前一个在数组中的下标,再就好找了。输入的处理方法要注意一下。 代码:#include #include #include #include #include #include #include #include using namespace std;#define N 100027struct node{ int flag; node *next[26];}*root;char dic[N][11];node *create(){ node *p; p = (nod... 阅读全文
posted @ 2014-02-11 16:47 whatbeg 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 线段树较复杂题,涵盖了线段树的大部分操作。 这题节点维护: ls:左边最长连续1的长度, rs:右边最长连续1的长度 , ms:整个区间的最长连续1的长度, sum:区间内1的个数 ,mark:操作懒标记 将取反操作单独做一个函数来处理。 具体维护见代码:#include #include #include #include #include using namespace std;#define N 100027struct node{ int ls,rs,ms; int sum; int mark;}tree[4*N];int a[N];int n,m;void pus... 阅读全文
posted @ 2014-02-07 13:27 whatbeg 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 字典树又一基本题代码:#include #include #include #include #include using namespace std;#define N 1027struct node{ int count; node *next[30];}*root;char ss[13];node *create(){ node *p; p = (node *)malloc(sizeof(node)); p->count = 1; for(int i=0;inext[i] = NULL; return p;}void release(node *... 阅读全文
posted @ 2014-02-03 14:29 whatbeg 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 字典树基本题。代码:#include #include #include #include #include #include using namespace std;#define N 1027struct node{ int count; node *next[30];}*root;char ss[N][30];node *create(){ node *p; p = (node *)malloc(sizeof(node)); p->count = 1; for(int i=0;inext[i] = NULL; return p;}void rel... 阅读全文
posted @ 2014-02-03 14:25 whatbeg 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 递归求解,代码不太好看,是2013年7月写的代码:#include#include#include#include#includeusing namespace std;char s[102][102];int flag[26];int res[28];int tag1[27];int zong,heng;int tag;int n,m;int zhao(int qix,int qiy,int zhx,int zhy){ int fff=0; for(int i=qix;i=2&&heng-j>=2) { for(... 阅读全文
posted @ 2014-02-02 11:23 whatbeg 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 树状数组,开始的时候wa了,后来看看,原来是概率论没学好,以为求(L,B) - (R,T) 矩阵内的和只要用sum(R+1,T+1) - sum(L,B) 就行了,。傻x了。。必须 sum(R,T) - sum(L,T) - sum(R,B) + sum(L,B) ; (R,T 已经自加1) 诫之。... 阅读全文
posted @ 2014-01-27 11:13 whatbeg 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 树状数组。代码:#include #include #include #include #include #include using namespace std;#define N 100010int vis[N],have[N];int low[N],high[N];int c[N];vect... 阅读全文
posted @ 2014-01-26 15:17 whatbeg 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 最裸的二维树状数组,但是因为内存太大(c[1010][1010]),好像不能运行,结果蒙着写,写了好久。。代码:#include #include #include #include #include using namespace std;#define N 1010int c[N][N];int lowbit(int x){ return x&(-x);}void modify(int x,int y,int val){ for(int i=x;i0;i-=lowbit(i)) { for(int j=y;j>0;j-=lowbit(j)) ... 阅读全文
posted @ 2014-01-25 11:49 whatbeg 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 这题用线段树的话简直就是一个水题。。不过刚学树状数组,要用一下。题意:每次给你a,b,表明a~b之间涂色,然后最后一次输出每个气球被涂色的次数。要用树状数组就要考虑怎么转化为前缀和问题,这题可以这样做:每次输入a,b,令A[a] = 1,A[b+1] = -1; 然后更新和,查询的时候容易知:a~b之间都被涂了一次,求前缀和结果也为一次,多次插入a,b,性质不变,插入后即可直接输出。复杂度很小,这也是树状数组的好处。。#include #include #include #include #include using namespace std;#define N 100100int c[N] 阅读全文
posted @ 2014-01-18 22:24 whatbeg 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 目前已学习:70等待学习: 251: 高级数据结构(17)线段树,并查集,后缀数组,树状数组,串的模式匹配(KMP),字典树(Trie),左偏树(可合并堆),单调队列,优先队列,AC自动机,二叉堆,伸展树,Treap,块状链表与块状树,树链剖分,动态树,可持久化数据结构,划分树,RMQ(Range... 阅读全文
posted @ 2014-01-09 12:31 whatbeg 阅读(388) 评论(1) 推荐(2) 编辑
摘要: 1.POJ 1733Parity gameTime Limit:1000MSMemory Limit:65536KTotal Submissions:5744Accepted:2233DescriptionNow and then you play the following game with y... 阅读全文
posted @ 2014-01-09 12:04 whatbeg 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 这题。。刚开始看那个数字有点大,以为开不了那么大的数组(其实只有一千万,可以开,,被眼睛给欺骗了。。),结果用了一些容器来优化,结果发现所谓的“优化”过后时间花费还更多了,多了一倍, 虽然空间复杂度提高了10倍。。真是。果然是一个时间复杂度换空间复杂度的活生生的案例啊。。这题给我的收获:1.1000... 阅读全文
posted @ 2014-01-07 11:34 whatbeg 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 这题用并查集来做,判断什么时候形成了环即判断什么时候加入的线段两个端点原先是属于同一集合的。对于一个点,有两个坐标x,y,不好做并查集操作,于是要用map来存储,即做成map形式,每加入一条线段,如果没有出现过这一个/两个端点,则赋此条线段一个/两个端点一个类型,然后找他的两个端点是否原先在同一个集... 阅读全文
posted @ 2014-01-04 19:16 whatbeg 阅读(236) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 下一页