自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

菜鸟成长ing

得之我幸,失之我命、

  • 博客(78)
  • 收藏
  • 关注

原创 HDU-1007 Quoit Design 最小距离点对

求平面内任意两点间距离1.蛮力法( 时间复杂度O(n^2) 适用于点的数目比较小的情况下)算法描述:已知集合S中有n个点,一共可以组成n(n-1)/2对点对,蛮力法就是对这n(n-1)/2对点对逐对进行距离计算,通过循环求得点集中的最近点对:2、分治法     1)算法描述:已知集合S中有n个点,分治法的思想就是将S进行拆分,分为2部分求最近点对。算法每次选择一

2013-11-29 20:10:49 1129

原创 割点模板

http://blog.csdn.net/u011742541/article/details/14104613int low[maxn],dfn[maxn];bool iscut[maxn];void tarjan( int u, int fa ){ low[u] = dfn[u] = ++time; int child = 0; for( int i = 0; i < m

2013-11-29 15:40:36 532 1

原创 最小生成树模板

#include#include#include#include#includeusing namespace std;const int maxn = 105;const double inf = 100000000.0;int n,m;double dis[maxn];bool vis[maxn];struct Node{ int x,y;}node[maxn];

2013-11-29 15:29:28 458

原创 多重背包模板

void CompletePacc(int cost,int weight) { int i; for(i=cost;i<=v;i++) if(dp[i]<dp[i-cost]+weight) { dp[i]=dp[i-cost]+weight; } }void Zero

2013-11-29 15:27:16 456

原创 并查集模板

int find( int x ){ if( p[x] == x ) return p[x]; else { return p[x] = find( p[x] ); }}void merge( int a,int b ){ int x = find(a); int y = find(b); if( ra

2013-11-29 15:25:45 471

原创 SPEA算法模板

http://blog.csdn.net/u011742541/article/details/12916609bool SPEA( int s ){ queueque; memset( outque,0,sizeof(outque) ); memset( vis,0,sizeof(vis) ); for( int i = 0; i < n; i ++ )

2013-11-29 15:23:26 3043

原创 BellmanFord算法模板

http://blog.csdn.net/u011742541/article/details/12916609bool BellmanFord( int s ){ for( int i = 0; i < n; i ++ ) dis[i] = inf; dis[s] = 0; for( int i = 0; i < n-1; i ++ ) //n

2013-11-29 14:09:39 730

原创 Floyd算法模板

http://blog.csdn.net/u011742541/article/details/12876415void Floyd(){ int temp=inf; for( int k=1;k<=max_city;k++ ) for( int i=1;i<=max_city;i++ ) if( map[i][k]!=inf ) for( int j=1;j<=m

2013-11-29 14:00:59 489

原创 Dijstra算法模板

http://blog.csdn.net/u011742541/article/details/12917981int maps[maxn][maxn],dis[maxn];bool vis[maxn];typedef pairpii;void Dijstra( int x ){ priority_queue,greater >que; memset( v

2013-11-29 13:57:58 645

原创 Hopcroft-Karp算法模板

http://blog.csdn.net/u011742541/article/details/14104573bool searchpath(){ queueque; dis = inf; memset( dx,-1,sizeof(dx) ); memset( dy,-1,sizeof(dy) ); for( int i = 1; i <= nx; i ++ ) {

2013-11-28 20:35:34 599

原创 KM模板

int Max( int a,int b ){ return a>=b?a:b;}bool findpath(int u) //给x[u]找匹配,这个过程和匈牙利匹配是一样的{ visx[u] = 1; for( int v=1; v<=ny; v++ ) { if( !visy[v] && lx[u] + ly[v] == map[u][v] )

2013-11-28 20:33:48 404

原创 Dinic模板

//多路增广bool Dinic_bfs( int st ){ queueque; for( int i = 0; i <= n; i ++ ) dis[i] = -1; dis[st] = 0; que.push(st); while( !que.empty() ){ int u = que.front(); que.pop(); for( int i = head[

2013-11-28 20:31:16 515

原创 ISPA模板

int SAP_Max_Flow( int st,int end ){ int curedge[maxn],pre[maxn],h[maxn],gap[maxn]; int u,neck,tmp,i; memset( h,0,sizeof(h) ); memset( gap,0,sizeof(gap) ); int cur_flow,flow_ans = 0; for( int i

2013-11-28 20:28:53 610

原创 HDU-4292 Food 三分图

#include "stdio.h"#include "queue"#include "algorithm"using namespace std;const int maxn = 810;const int inf = 1<<30;int n,m,pos;struct Node{ int v,w,next; Node() {}; Node( int v,int w,int

2013-11-27 23:02:02 565

原创 POJ-3469 Dual Core CPU 网络流

题意:一台双核电脑,给你多个任务,分别给出每个任务在第一个核和第二个核上运行的消耗。后面的m行输入是给出两个任务在两个不同核上运行需要付出的额外消耗。建图:把每个任务作为节点,在超级源点与任务间的连一条边,其容量为给任务在核1上运行的消耗,在该任务节点与超级汇点之间连一条边,容量为该任务在核2上运行的消耗。           在任务之间连接无向边,容量为两个任务不在同一核上运行的

2013-11-27 18:08:01 594

原创 网络流学习总结

最大流基本算法:  EK、Dinic、Sap、Isap最大流算法分析题意 --->建立模型 --->构造网络 --->解决问题最小费用最大流方格取数

2013-11-25 18:40:04 398

原创 FAFU-1198 小三大作战 小三大作战

http://acm.fafu.edu.cn/problem.php?id=1198                                                                                                 小三大作战Time Limit:2000MSMemory Limit:65536KB

2013-11-25 10:34:49 630

原创 HDU-1565 方格取数(1) 网络流

http://acm.hdu.edu.cn/showproblem.php?pid=1565题意:给你一个n*n的格子的棋盘,每个格子里面有一个非负数。从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大。算法分析:最大独立点集 = 总点数 - 最小点覆盖集 独立集:独立集是指图的顶点集的一个子集,该

2013-11-23 22:50:27 1276

原创 面积

#include "stdio.h"#include "algorithm"using namespace std;const int maxn = 2010;int n;double y[maxn];struct node{ double x,y1,y2; //x 边的位置 y边的区间大小 int f; //f 标记 前边还是

2013-11-23 11:11:43 485

原创 HDU-1426 数独 搜索

http://acm.hdu.edu.cn/showproblem.php?pid=1426全暴力 注意输入格式比较坑#include#include#include#include#includeusing namespace std;const int maxn = 15;const int inf = 1<<30;int pos;int map[maxn][

2013-11-20 21:57:59 657

原创 HDU-1518 Square 搜索

http://acm.hdu.edu.cn/showproblem.php?pid=1518经典DFS+截枝#include#include#include#includeusing namespace std;const int maxn = 105;const int inf = 1<<30;int n,flag,L;int len[maxn];bool vis[ma

2013-11-20 18:22:25 670

原创 HDU-1401 Solitaire 搜索

题意:8*8的棋盘 固定4个棋子 问能否在8步以内(包括8步)从一个状态移动到另个状态 移动的时候如果所移动的位置也是棋子 可以直接跳过 (类似跳棋)暴力搜索 8维数组表示状态恶心的要死 QAQ MLE 压入栈的时候加了个条件后AC#include #include #include using namespace std;const int maxn = 8;bool

2013-11-20 17:02:20 630

原创 HDU-1547 Bubble Shooter 搜索

http://acm.hdu.edu.cn/showproblem.php?pid=1547 注意奇偶方向 #include "stdio.h"#include "string.h"const int maxn = 105;int h,w,sx,sy,ans;int xs[][6] = { {0,-1,-1,0,1,1},{0,-1,-1,0,1,1}};int y

2013-11-18 21:06:05 1075

原创 HDU-1584 蜘蛛牌 搜索

http://acm.hdu.edu.cn/showproblem.php?pid=1584#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 15;const int inf = 1<<30;int

2013-11-17 19:35:37 466

原创 HDU-1455 Sticks 经典dfs剪枝

http://acm.hdu.edu.cn/showproblem.php?pid=1455#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 105;const int inf = 1<<30;int n,po

2013-11-17 16:51:01 560

原创 HDU-1043 Eight 八数码问题

http://acm.hdu.edu.cn/showproblem.php?pid=1043#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 105;const int inf = 1<<30;int xs[]

2013-11-13 21:25:06 489

原创 HDU-1728 逃离迷宫

http://acm.hdu.edu.cn/showproblem.php?pid=1728注意行列反了 用经过每个点的最小转弯数来标记点是否压入队列#include#include#include#include#include#include#includeusing namespace std;const int maxn = 105;const int

2013-11-13 13:17:15 403

原创 HDU-1732 Push Box BFS + BFS

http://acm.hdu.edu.cn/showproblem.php?pid=1732推三个箱子 难点主要是状态表示#include#include#include#include#include#include#includeusing namespace std;const int maxn = 8;int n,m,pos;char map[max

2013-11-12 14:58:34 579

原创 FAFU-1255 哈夫曼树及编码

http://acm.fafu.edu.cn/problem.php?id=1255//优先队列#include#include#include#include#include#include#includeusing namespace std;const int maxn = 505;const int inf = 1<<30;int root,len,

2013-11-08 16:27:18 600

原创 HDU-1175 连连看 DFS

#include#include#include#include#include#include#includeusing namespace std;const int maxn = 1005;const int inf = 1<<30;int n,m;int x1,x2,y1,y2,flag;int map[maxn][maxn];int xs[] = {0,1,0

2013-11-06 18:41:34 511

原创 HDU-1180 诡异的楼梯

迷宫 就多了个楼梯的问题 可以停在原点 楼梯是瞬间通过#include#include#include#include#include#include#includeusing namespace std;const int maxn = 25;const int inf = 1<<30;int n,m;char map[maxn][maxn];int x

2013-11-06 17:59:45 580

原创 HDU - 1104 Remainder 搜索

本题是bfs,不过有点小阴谋,在num因为大量运算时会很大,于是我们要取余,但不能直接用%k,而是用%km(k*m),因为不止要和k线性同余还要和m线性同余,也就是说,如果只用%k,那么我对n做了一步处理后,产生的结果只对k线性同余,假如下一步用%m,那么就错了比如,8 3,10,op为+%,如果用%k,答案就是2,但正确答案是1。#include#include#incl

2013-11-06 10:39:33 584

原创 HDU-1233 还是畅通工程 并查集加Kruskal

#include #include #include using namespace std;int n,ans;int p[105];struct node{ int s,e,dis;}road[5000];bool cmp( node a,node b){ return a.dis<b.dis;}int find(int x){ return x!=p[x]

2013-11-04 22:48:37 557

原创 HDU-1233 还是畅通工程 最小生成树Prime

#include#include#include#include#includeusing namespace std;const int maxn = 105;const double inf = 100000000.0;int n,m;double dis[maxn];bool vis[maxn];struct Node{ int x,y;}node[maxn];

2013-11-04 22:44:31 563

原创 HDU-1879 继续畅通工程 prime

#include "stdio.h"#include "string.h"const int maxn = 105;const int inf = 1<<30;int n;int map[maxn][maxn],dis[maxn];bool vis[maxn];int prime(){ int i,j,min,pos,ans = 0; //起点 答案 vis[1

2013-11-04 21:23:02 565

原创 HDU-387 Invade the Mars 最短路

/* 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3873 最短路的巧妙运用,本题较最短路问题多出了保护城市的条件,即一个城市x受若干城市保护,没有攻占所有保护x的“卫星城”就不可以攻占x dij过程中要维护其保护城市,用les[x]记录x所有“卫星城”被攻占的最早时间,那么能到x的最短时间为les[x]和到达x的最短路中的较大者 处理特点

2013-11-04 20:30:22 738

原创 poj-1273 Drainage Ditches 最大流

/*http://poj.org/problem?id=1273裸最大流*///EK算法#include "stdio.h"#include "queue"using namespace std;const int maxn = 205;int map[maxn][maxn],path[maxn]; //邻接数组 前驱数组int n,m;bool E

2013-11-03 14:11:21 829

原创 Tarjan算法

#include#includeint DFN[105]; //dfn[i]表示dfs时达到顶点i的时间int Low[10005]; //low[i]表示i所能直接或间接达到时间最小的顶点。bool map[105][105];bool mark[105];int stack[105];int ti

2013-11-03 14:09:59 618

原创 POJ-1144 Network 求割点

// 佳哥版本 32 ms#include#include#includeusing namespace std;const int maxn = 105;int n;int time;vectormap[maxn];int low[maxn],dfn[maxn];bool iscut[maxn];void tarjan( int u, int fa ){ low[u]

2013-11-03 14:09:38 616

原创 poj 2942 圆桌武士 双连通分量(BCC)+二分图+奇圈判断

//http://blog.csdn.net/lyy289065406/article/details/6756821//刘汝佳版/*大致题意:亚瑟王要在圆桌上召开骑士会议,为了不引发骑士之间的冲突,并且能够让会议的议题有令人满意的结果,每次开会前都必须对出席会议的骑士有如下要求:1、 相互憎恨的两个骑士不能坐在直接相邻的2个位置;2、 出席会议的骑士数必须是奇数,这是为了让投票表

2013-11-03 14:09:13 1053

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除