摘要: 最小费用,最大流的思想,也不知道怎么稀里糊涂就ac啦#include <iostream> #include <cstring> #include <queue> using namespace std; const int maxn=102; const int inf=2<<20; int cost[maxn][maxn],flow[maxn][maxn],cap[maxn][maxn],d[maxn]; int n,m; int solve() { queue<int> q; int i,vis[maxn],p[maxn],to 阅读全文
posted @ 2012-11-08 14:45 LJ_COME!!!!! 阅读(146) 评论(0) 推荐(0)
摘要: 刚开始是用的邻接矩阵,一直wa,后来看了其他人的代码,又想了想,两个点之间有多条路径,不能只存储权值最小的,因为每个路径都可能是一个最短路的组成部分(但现在还不是想的太清楚),所以有多少条边,就存多少边的信息bellman-ford#include <iostream> using namespace std; const int maxn=501; const int inf=2<<20; int d[maxn],w[maxn*maxn],u[maxn*maxn],v[maxn*maxn]; int f,n,m,wm,t; bool bellman() { int i 阅读全文
posted @ 2012-11-04 20:14 LJ_COME!!!!! 阅读(134) 评论(0) 推荐(0)
摘要: bellman-ford算法,此题可看做最短路径问题,原因是,可把到源点的距离看做负值(自己建立的一个抽象模型,但不表示出来,考虑的时候按这个负值模型考虑)。那么求解此题,就是看有没有至少一个负权环,如果有的话,因为根据此题可知,所以包含这个负权环的任一路径且在这个负权环之后的所有节点都会是无穷小,源点到源点的某一路径一定包含这个负权环,所以只要这个负权环走过一定次数,一定会导致源点到源点的距离小于初始值,其实就是题目要求的大于初始值。不需要考虑正权环抵消对结果的影响,因为如果有正权环,完全可以不走这个正权环。因为从源点返回源点,至少会经过一个环,但如果没有负权环,就不会使得到的新距离小于初始 阅读全文
posted @ 2012-11-03 19:03 LJ_COME!!!!! 阅读(139) 评论(0) 推荐(0)
摘要: 最短路径问题,我用的是临接表来存储各个边的信息,用优先队列的dijkstra算法#include <iostream> #include <queue> #include <vector> using namespace std; const int maxn=101; const int INF=2<<20; struct edge { int po,w; edge * next; }; struct node { edge * first; }head[maxn]; typedef pair<int,int>pii; priori 阅读全文
posted @ 2012-10-29 16:25 LJ_COME!!!!! 阅读(125) 评论(0) 推荐(0)
摘要: 刚开始没有理解题意,以为是最短路径,后来才发现是prim,哎,无语。。。#include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxn=201; const double INF=2<<20; double x[maxn],y[maxn],edge[maxn][maxn]; int n; double getd(int k,int j) { double ex=(x[k]-x[j])*(x[k]-x[j]); double ey= 阅读全文
posted @ 2012-10-27 15:57 LJ_COME!!!!! 阅读(92) 评论(0) 推荐(0)
摘要: 单源最短路径,此题主要是要理解题目的意思。根据“他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。”这句话可知,一定要在一符合要求的区间(这个区间的上限和下限要符合等级限制,并且要包括编号1)里找,然后把所有符合要求的区间的值进行比较,从而得到在限制条件下的最短路径#include <iostream> using namespace std; #define maxn 201 #define INF 2<<20 int edge[maxn][maxn]; int inlim[maxn],lev[maxn],val[ 阅读全文
posted @ 2012-10-26 20:05 LJ_COME!!!!! 阅读(106) 评论(0) 推荐(0)
摘要: 最小生成树的基本知识,此图很稠密,所以选用Prim算法要快,Prim O(n2),Kruckal O(elog2e),向此题,e代表边数,远大于n,顶点数,所以选Prim#include <iostream> using namespace std; const int maxn=2001; char s[maxn][7]; int edge[maxn][maxn]; int lit[maxn]; int chan(int a,int b) { int amou=0; for(int i=0;i<7;i++) { if(s[a][i]!=s[b][i]) amou++; } 阅读全文
posted @ 2012-10-25 20:27 LJ_COME!!!!! 阅读(162) 评论(0) 推荐(0)
摘要: trie树水题#include <iostream> using namespace std; typedef struct node { char data; int count; node * next[26]; node * parent; node() { count=0; memset(next,0,sizeof(next)); } }trie; trie * r; void insert(char * s)//把单词插入trie树中 { if(r==NULL) r=new trie; trie * p=r; int di; while(*s!='\... 阅读全文
posted @ 2012-10-20 16:27 LJ_COME!!!!! 阅读(132) 评论(0) 推荐(0)
摘要: 优先队列或者说是堆得应用,最暴力的想法就是没输出一个最小值,更新,然后再排序,若用快排,时间效率为O(knlgn),但不需要对所有的排次序,所以就用到最小堆#include <iostream> #include <queue> #include <string> using namespace std; typedef struct node { int n,p,r; }ar; bool operator<(ar a,ar b) { if(a.p==b.p) return a.n>b.n; else return a.p>b.p; } p 阅读全文
posted @ 2012-10-18 23:42 LJ_COME!!!!! 阅读(85) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; const int maxn=8000+10; struct node { int l,r,len; }tree[maxn*3]; void Create(int p,int l,int r) { tree[p].l=l; tree[p].r=r; tree[p].len=r-l+1; if(l!=r) { int mid=(l+r)/2; Create(2*p+1,l,mid); Create(2*p+2,mid+1,r); } } int find(int p,int am) { ... 阅读全文
posted @ 2012-10-18 23:25 LJ_COME!!!!! 阅读(125) 评论(0) 推荐(0)