摘要:不知道为什么就那才那么AC了。。。后来想想,我在判断该边能不能加的时候确实是错了的。。不过也不至于MLE啊。。。MLE的好惨啊。。找不出错。。一开始写的dijkstra,发现错了。。。并不是二维标记。。然后改成spfa就行了。。用的优先队列以及map映射,写起来还是挺好写的。。#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<queue>#include<string>using namespace std;const int
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:题目: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.
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2767今天在做图论专题的时候碰到了这题,这样的话,正好学习了来写篇博客吧题目意思就是,给你一个有向网络图,问,至少加多少条边能使这个图成强连通那么就是要,先把图跑一遍targan,如果这个图是强连通,那么就输出0了,否则缩点,然后求所有点入度为0和出度为0个数的最大值了主要理解的地方就是缩点的那个地方,要理解belong数组的含义,以及为什么是求入度0和出席0的最大值证明我是不知道= =,真的是只能意会么 ?#include<cstdio>#include<cstring>#inclu
阅读全文
摘要: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...
阅读全文
摘要: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
阅读全文
摘要: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])){ ...
阅读全文
摘要: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
阅读全文
摘要:第一种是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,
阅读全文
摘要:我这个只是模板啦。。。用的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); ...
阅读全文
摘要:至于数状数组是怎么来的,这个得找资料了。。。也不知道怎么上传。。所以我也不讲了可以参考这个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
阅读全文
摘要: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 --;}对于这一段,开始用最小的加最大的,如果和小于要查找的...
阅读全文
摘要:昨天总结MST的模板,也写的差不多了吧总之两种方法,kruskal和prim麻烦的可能就是生成MST的唯一性的判定原理很简单,先找MST,然后枚举MST上每条边,方法是删除该边再找MST,如果能找到MST并且权值等于第一次找到的,就不唯一了http://poj.org/problem?id=1679# include <iostream># include <cstdio># include <algorithm># include <cstring>using namespace std;//先求出最小生成树,然后删除这棵树上的每条边求MST,
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4325这题看了数据就会发现,数据都很小的。。。。所以直接暴力能过当然开始我用的线段树后来想到,既然离散化了,那来暴力试试吧所以当作学习吧,同时学习了unique这个函数了用unique之前最好先排序一开始我以为unique是去除所有相同元素,哪想到其实也是个排序罢了#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 100000 + 10;int a
阅读全文
摘要:dfs //http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3631 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[40]; int b[40]; int ans; int n, m; /* void dfs(int k, int sum) { if(ans == m)return; if(k == 0){ ans = max(sum, ans); ...
阅读全文
摘要:我只想说,被坑了总以为这本书上没有错。。。却出现了两个错误书上用的指针邻接表,我想学下数组模拟,然后就全改了一个点表示一个事件,一条边表示该活动的时间那么对于每个事件和每个活动都有最早可能开始时间和最迟允许开始时间了具体思路也不想写了,本想画个图来写篇博客。。浪费时间啊。。时间宝贵啊。。贴代码吧。。#include<cstdio>#include<cstring>const int maxn = 10000;//顶点个数最大值const int maxm = 10000;//边数最大值struct node{ int to, w, id;//边的另一个顶点,持续时间,活
阅读全文
摘要:前天CUG比赛的D题,也就是POJ3250题http://poj.org/problem?id=3250正好拿来学习了下单调队列了#include<cstdio>#include<cstring>const int maxn = 100000 + 10;int maxq[maxn];int ind[maxn];int q[maxn];int n;int a[maxn];long long ans = 0;void calc(){ int head = 1, tail = 0; for(int i = 1; i <= n; i ++){ while(head <
阅读全文