LouZhang

导航

随笔分类 -  ACM

1 2 下一页

HDU4522
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4522好久没写了来写一篇吧#include <cstdio>#include <cstring>using namespace std;int q, n, t, d1, d2, a, b;char s[1010][10000+10];int k[1010];int g[210][210];int gg[210][210];const int inf = 99999999;void make(){ for(int i = 1; i <= n; i ++) for(int j = 1 阅读全文

posted @ 2013-03-27 10:40 louzhang_swk 阅读(305) 评论(0) 推荐(0) 编辑

KMP的个人理解
摘要:贴图什么的太麻烦了看下K哥的博客吧:http://972169909-qq-com.iteye.com/blog/1114968讲的很好啊,关于next数组的意义(当然我觉得他博客有点错误)其实就是一个模式串在一个主串中查找通过KMP可以快速找到要查找的位置,次数,长度等等。。。暴力做法当然是O(m*n),用了KMP就是O(m+n)了璐神的纯裸KMP(查找第一次出现的位置)#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int inf=100000 阅读全文

posted @ 2012-10-19 13:09 louzhang_swk 阅读(196) 评论(0) 推荐(0) 编辑

2-sat的一些总结
摘要:暑假还以为2-sat就是求强连通分量呢原来不仅如此啊贴个链接。。。写的很好啊http://www.cppblog.com/y346491470/articles/156782.html比较明显的2-Sat问题,关键是要把所有情况考虑完全。用x表示该变量取0,x’表示取1,下面说下如何构图:a and b == 1, 这种情况a和b必须取1,所以连边a->a', b->b'.a and b == 0,这种情况a和b不能同时为1,所以连边a'->b, b'->a.a or b == 1, 这种情况a和b不能同时为0,所以连边a->b&# 阅读全文

posted @ 2012-10-19 12:51 louzhang_swk 阅读(184) 评论(0) 推荐(0) 编辑

poj_2762,弱连通
摘要:http://poj.org/problem?id=2762这题是求弱连通弱连通就是无向图强连通(基图是有向图)思路:先targan缩点,然后这些点求最长链也就是这些点(缩点)在一棵树上,这棵树的深度应该为强连通分量个数。。画个图就好理解了#include<cstdio>#include<cstring>const int maxn(1111);struct Edge{ int v, next;}e1[maxn*6], e2[maxn*6];int head1[maxn], cnt1, head2[maxn], cnt2;int low[maxn], dfn[maxn] 阅读全文

posted @ 2012-09-06 12:13 louzhang_swk 阅读(228) 评论(0) 推荐(0) 编辑

poj_2728,最优比率生成树
摘要:http://poj.org/problem?id=2728上次也做过类似的,就是花费和路径的比值最小,不过和这不一样。。。。证明就网上搜吧。。一大堆。。我这是看别人的代码写的,迭代。。。错在精度上搞好久了。。。#include<cstdio>#include<cstring>#include<cmath>const int maxn(1010);#define inf 999999999int n;double g[maxn][maxn], cost[maxn][maxn];int vis[maxn];double dist[maxn];double x[ 阅读全文

posted @ 2012-09-04 22:20 louzhang_swk 阅读(221) 评论(0) 推荐(0) 编辑

poj_2584,多重二分匹配
摘要:http://poj.org/problem?id=2584原理和普通二分匹配一样多重二分匹配也可以像普通二分匹配那样,通过拆点建图用最大流来解作为自己的模板吧#include<cstdio>#include<cstring>int g[30][30];int smlxt[30];char s[15];int n;int link[30][30], vlink[30], vis[30];int f(char c){ if(c == 'S') return 1; if(c == 'M') return 2; if(c == 'L&# 阅读全文

posted @ 2012-09-02 17:57 louzhang_swk 阅读(211) 评论(1) 推荐(1) 编辑

poj_2267
摘要:不知道为什么就那才那么AC了。。。后来想想,我在判断该边能不能加的时候确实是错了的。。不过也不至于MLE啊。。。MLE的好惨啊。。找不出错。。一开始写的dijkstra,发现错了。。。并不是二维标记。。然后改成spfa就行了。。用的优先队列以及map映射,写起来还是挺好写的。。#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<queue>#include<string>using namespace std;const int 阅读全文

posted @ 2012-08-28 13:50 louzhang_swk 阅读(244) 评论(0) 推荐(0) 编辑

hdu_4391,线段树
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4391不想我说了,调了好久不会这。。#include<cstdio>#include<cstring>const int maxn(111111);#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define ll rt<<1#define rr rt<<1|1int max[maxn<<2], min[maxn<<2], sum[maxn<<2 阅读全文

posted @ 2012-08-24 15:46 louzhang_swk 阅读(372) 评论(0) 推荐(1) 编辑

hdu_4396,二维最短路
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4396比赛的时候怎么写怎么错。。还TLE。。还MLE。。还RE。。dijkstra#include<cstdio>#include<cstring>#include<queue>using namespace std;const int maxn(5005);const int maxe(100010);const int inf(100000000);struct Edge{ int v, w, next;}e[maxe*2];int head[maxn], cnt;in 阅读全文

posted @ 2012-08-24 13:42 louzhang_swk 阅读(344) 评论(0) 推荐(0) 编辑

第一场个人图论专题
摘要:http://poj.org/problem?id=1062枚举层次求最短路,比如酋长等级是5,m是2,那么就要枚举等级在3-5, 4-6, 5-7之间这三种情况的最短路里面的最小值了以前做过,不过这次做还是一直wa。。。原来是我在dijkstra初始化dist数组的时候出问题了。。弱爆了啊。。wa的真辛苦poj_1062#include<cstdio>#include<cstring>const int maxn = 110;int g[maxn][maxn];int dist[maxn], vis[maxn];int flag[maxn];int m, n;int 阅读全文

posted @ 2012-08-21 15:17 louzhang_swk 阅读(225) 评论(0) 推荐(0) 编辑

混合图欧拉路径问题
摘要:题目:http://poj.org/problem?id=1637这是转载的 http://www.cnblogs.com/destinydesigner/archive/2009/09/28/1575674.html1 定义欧拉通路 (Euler tour)——通过图中每条边一次且仅一次,并且过每一顶点的通路。欧拉回路 (Euler circuit)——通过图中每条边一次且仅一次,并且过每一顶点的回路。欧拉图——存在欧拉回路的图。2 无向图是否具有欧拉通路或回路的判定G有欧拉通路的充分必要条件为:G 连通,G中只有两个奇度顶点(它们分别是欧拉通路的两个端点)。G有欧拉回路(G为欧拉图):G. 阅读全文

posted @ 2012-08-20 16:43 louzhang_swk 阅读(975) 评论(1) 推荐(0) 编辑

hdu_2767,加边至强连通
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2767今天在做图论专题的时候碰到了这题,这样的话,正好学习了来写篇博客吧题目意思就是,给你一个有向网络图,问,至少加多少条边能使这个图成强连通那么就是要,先把图跑一遍targan,如果这个图是强连通,那么就输出0了,否则缩点,然后求所有点入度为0和出度为0个数的最大值了主要理解的地方就是缩点的那个地方,要理解belong数组的含义,以及为什么是求入度0和出席0的最大值证明我是不知道= =,真的是只能意会么 ?#include<cstdio>#include<cstring>#inclu 阅读全文

posted @ 2012-08-19 12:40 louzhang_swk 阅读(778) 评论(0) 推荐(0) 编辑

网络流sap需要注意的地方
摘要:int sap(){ memset(level, 0, sizeof level); memset(gap, 0, sizeof gap); memset(cur, 0, sizeof cur); int u = pre[s] = s; int aug = inf; gap[s] = n;这个要使源点gap值为点个数 int v; int flow = 0; while(level[s] < n){ for(v = cur[u]; v < n; v ++){ if(c[u][v] > 0 && level... 阅读全文

posted @ 2012-08-17 15:50 louzhang_swk 阅读(257) 评论(0) 推荐(0) 编辑

hdu_1269, 强连通分量的学习
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1269#include<cstdio>#include<cstring>const int maxn = 10000 + 10;struct Edge{ int to, next;}e[maxn*10];int head[maxn], index;int dfn[maxn], low[maxn];int belong[maxn], vis[maxn];int step, color;void add_edge(int u, int v){ e[index].to = v, e[inde 阅读全文

posted @ 2012-08-12 21:25 louzhang_swk 阅读(230) 评论(0) 推荐(0) 编辑

hdu_2063,二分图最大匹配的学习
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2063也拿这个当模板吧。。。#include<cstdio>#include<cstring>int k, m, n;bool g[510][510];int visit[510], link[510];bool dfs(int u){ for(int i = 1; i <= n; i ++){ if(g[u][i] && !visit[i]){ visit[i] = 1; if(link[i] == -1 || dfs(link[i])){ ... 阅读全文

posted @ 2012-08-12 16:34 louzhang_swk 阅读(158) 评论(0) 推荐(0) 编辑

poj_2516,最小费用最大流
摘要:http://poj.org/problem?id=2516参考这篇博客写的。。。http://www.cppblog.com/Icyflame/archive/2009/06/30/88941.html这几天算是被网络流整死了,算法太复杂了,理解起来确实是难。。2516#include<cstdio>#include<cstring>const int inf = 10000000;const int maxn = 110;struct Edge{ int u, v, w, c, next;}e[maxn * maxn * 4];int head[maxn], ind 阅读全文

posted @ 2012-08-12 14:00 louzhang_swk 阅读(218) 评论(0) 推荐(0) 编辑

poj_1459,sap的三种写法
摘要:第一种是BFS的SAPbfs+sap#include<cstdio>#include<cstring>using namespace std;const int inf = 100000000;//不要开太大int n, np, nc, m;const int maxn = 105;int c[maxn][maxn];//残留网络int s, t;int level[maxn], gap[maxn];//层次网络, 层结点数(用于间隙优化)int q[maxn], pre[maxn];//队列, 前驱void init_sap(){ memset(level, 10, 阅读全文

posted @ 2012-08-11 17:20 louzhang_swk 阅读(289) 评论(0) 推荐(0) 编辑

欧拉路径问题
摘要:我这个只是模板啦。。。用的fleury算法。。。当然也可以DFS求路径。。。原理感觉一样,只不过这更高效吧。。#include<cstdio>#include<cstring>int n,m;int e[100][100];int top;int stack[100];void dfs(int x){ top ++; stack[top] = x; for(int i = 1; i <= n; i ++){ if(e[x][i] > 0){ e[i][x] = e[x][i] = 0;//删除此边 dfs(i); ... 阅读全文

posted @ 2012-08-08 15:31 louzhang_swk 阅读(714) 评论(0) 推荐(1) 编辑

hdu_1166,树状数组的学习
摘要:至于数状数组是怎么来的,这个得找资料了。。。也不知道怎么上传。。所以我也不讲了可以参考这个http://blog.csdn.net/cambridgeacm/article/details/7771782http://acm.hdu.edu.cn/showproblem.php?pid=1166这题是很经典的题,最开始是学线段树的时候做的,这次学树状数组,又做了一遍#include<cstdio>#include<cstring>const int maxn = 50000 + 10;int a[maxn], c[maxn];int n;inline int lowbi 阅读全文

posted @ 2012-08-03 12:26 louzhang_swk 阅读(190) 评论(0) 推荐(0) 编辑

hdu_4334,线性查找的学习
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4334这题开始做的时候,不是O(n^2)*O(logn^3) MLE就是O(n^3)*O(logn^2) TLE了后来看解题报告都没看懂幽幽子大神给我讲了下,真的是恍然大悟啊while(j < cnt1 && k >= 0){ if(f[j] + g[k] == -tmp){ flag = 1; break; } if(f[j] + g[k] < 0 - tmp) j ++; else k --;}对于这一段,开始用最小的加最大的,如果和小于要查找的... 阅读全文

posted @ 2012-08-02 19:42 louzhang_swk 阅读(563) 评论(0) 推荐(0) 编辑

1 2 下一页
点击右上角即可分享
微信分享提示