
模板
_Yyg
这个作者很懒,什么都没留下…
展开
-
poj 1236 Network of Schools (强连通分量+缩点)
思路:首先用tarjan算法算出每个点属于哪个连通块,再缩点后求出各个连通块的入度出度。 入度为0的点的个数就是问一的解。 入度和出度为0的点个数多的就是问二的解。 代码: #include #include #include #include using namespace std; const int maxn = 119; int n , in[ma原创 2013-07-29 11:17:57 · 523 阅读 · 0 评论 -
hdu 4725 The Shortest Path in Nya Graph (SPFA+SLF优化)
#include #include #include #include using namespace std; const int maxn = 100500; const int inf = 0x3f3f3f3f; int t , n , m , c , vis[maxn * 4] , cnt[maxn * 4] , dist[maxn * 4] , cc , a , b; struct原创 2013-09-17 17:57:34 · 508 阅读 · 0 评论 -
hdu 1874 畅通工程续 (SPFA模板)
#include #include #include const int maxn = 70010; const int inf = 0x3f3f3f3f; using namespace std; int vis[maxn] , cnt[maxn] , dist[maxn] , n , m , c , a , b; struct G{ int head[maxn] , e;原创 2013-09-12 20:28:33 · 485 阅读 · 0 评论 -
poj 1861 Network (kruskal 最小生成树)
#include #include #include const int maxn = 15005; int n , m , fa[maxn] , rank[maxn]; struct T{ int u , v , c; }edge[maxn * 2] , edge1[maxn * 2]; void init(){ for(int i = 1 ; i <= n ; i ++原创 2013-09-05 20:09:53 · 532 阅读 · 0 评论 -
hdu 3371 Connect the Cities (Kruskal+ 并查集)
#include #include #include const int maxn = 255003; int fa[maxn] , rank[maxn] , n , m , k , p , q , c , tot , head[maxn] , ans , cnt; struct T{ int u , v , c , next; }edge[maxn * 2]; int cmp(原创 2013-09-05 19:36:37 · 445 阅读 · 0 评论 -
hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (多重背包)
#include #include #include using namespace std; int dp[109]; int cost[109]; int value[109]; int country[109]; int volume; void ZeroOne(int cost,int value) { for(int i=volume;i>=cost;i--) d原创 2013-09-04 17:11:13 · 616 阅读 · 0 评论 -
hdu 1114 Piggy-Bank (完全背包)
#include #include #include using namespace std; const int maxn = 505; const int inf = 0x3f3f3f3f; int n; int w[maxn] , c[maxn] , E , F , V , dp[maxn * 10000]; int main(){ int t; scanf("%d"原创 2013-09-03 20:06:49 · 593 阅读 · 0 评论 -
hdu 4619 Warm up 2 (二分匹配)
#include #include const int maxn = 1005; int n , m; int g[maxn][maxn]; int linker[maxn]; bool used[maxn]; struct T1{ int x1; int y1; int x2; int y2; }pn[maxn]; struct T2{ int x1;原创 2013-08-11 19:14:49 · 503 阅读 · 0 评论 -
hdu 2255 奔小康赚大钱 (KM算法 二分图最佳完美匹配 模板)
模板题 代码: #include #include #include #include using namespace std; /* KM算法 * 复杂度O(nx*nx*ny) * 求最大权匹配 * 若求最小权匹配,可将权值取相反数,结果取相反数 * 点的编号从0开始 */ const int N = 310; const int INF = 0x3f3f3转载 2013-08-11 16:54:53 · 795 阅读 · 0 评论 -
hdu 4691 Front compression (后缀数组)
#include #include #include #define max(a,b) ((a)>(b)?(a):(b)) using namespace std; const int MAX = 200050; int sa[MAX], rank[MAX], height[MAX]; int wa[MAX], wb[MAX], wv[MAX], wd[MAX]; char str[MAX];原创 2013-08-20 18:16:34 · 531 阅读 · 0 评论 -
hdu 4587 TWO NODES
#include #include #include using namespace std; const int maxn = 5008; int head[maxn] , low[maxn] , pre[maxn] , depth , iscut[maxn] , instack[maxn]; int n , m , e , a , b , ret , del; struct T{原创 2013-08-20 10:36:19 · 641 阅读 · 0 评论 -
hdu 4587 TWO NODES (割点)
#include #include #include using namespace std; const int maxn = 5008; int head[maxn] , low[maxn] , pre[maxn] , depth , iscut[maxn] , instack[maxn]; int n , m , e , a , b , ret , del; struct T{原创 2013-08-20 10:30:53 · 102 阅读 · 0 评论 -
poj 2513 Colored Sticks (字典树+并查集判连通)
代码: #include #include #include typedef struct TrieNode{ struct TrieNode *next[27]; int flag; int id; }Trie; int n , tot; Trie tree[5100005]; int father[510005]; int rank[510005]; int in原创 2013-07-27 16:10:57 · 507 阅读 · 0 评论 -
uVA 10600 ACM Contest and Blackout (prim求次小生成树)
use标记当前边是否属于最小生成树。 d[i][j]代表从i->j的瓶颈路。 #include #include #include using namespace std; const int inf = 0x3f3f3f3f; int n , m , a , b , c; int map[105][105]; int dist[105] , vis[105] , ans1 , an原创 2013-09-26 10:26:53 · 581 阅读 · 0 评论