自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(17)
  • 收藏
  • 关注

原创 背包问题

最近开始复习dp 又看了一遍背包九讲这种大神级论文 多重背包:poj 1014 dividing 将多重背包拆分,转换成01背包 Problem: 1014   User: hcy_ray Memory: 416K   Time: 16MS Language: C++   Result: Accepted #include

2011-11-26 13:56:58 326

原创 poj 1364 King

本题构造s[x]=a[1]+a[2]+a[3]+…+a[x] 则a[i]+…+a[i+n]=s[i+n]-s[i-1] 此后用bellman-ford 需要构造超级源点   #include #include #include #include #include struct edge{ int u,v,w; }edges[500001]; char ch[100];

2011-11-22 20:35:47 278

原创 poj 2983 Is the Information Reliable?

等号的情况可以转换成不等式 a=b 就可以表示成a>=b  b>=a 约束条件写出来就用bellman-ford 需要注意的是要构造超级源点     #include #include #include #include #include struct edge{ int u,v,w; }edges[500001]; char ch[100]; int dist[1

2011-11-21 20:52:39 385

原创 poj 3169 Layout

今天才知道差分约束这种神奇的东西 但三角不等式还是不熟  构造时错了很多次 #include #include #include #include #include struct edge{ int u,v,w; }edges[500000]; int dist[1001]; int main() { int n,ml,md,m; scanf(

2011-11-18 23:02:06 276

原创 poj 3259 Wormholes(Bellman-Ford)

题目一直很迷茫直到看到别人写的题目大意才知道普通路径是双向的,而虫洞就是负权值的边 剩下的就是判断负权值回路     #include #include #include #include #include #include using namespace std; struct edge { int u,v,w; }edges[50000]; i

2011-11-18 18:06:21 334

转载 最短路径

POJ 1201 Intervals 差分约束系统 设S(i)为 0..i-1 中在最终序列中的的整数个数。则约束条件如下: S(b)-S(a) >= c 0 S(i+1)-S(i) >= 0;                              S(i)-S(i+1) >= -1 注意本题要求的是最小值, 而按照>=号建图后发现图中有负环, 怎么办呢? 其实很简单, 本题求的

2011-11-17 19:36:06 301

原创 poj 2485 Highways

依旧是最简单的最小生成树 这次用prim去写(万恶的Presentation Error)     #include #include #include #include #include using namespace std; int flag[501]; int f[501][501]; int main() { int T;int min[50

2011-11-17 19:30:59 225

原创 poj 2421 Constructing Roads

给定部分路径后的最小生成树 注意给的路径有可能构成回路     #include #include #include #include #include using namespace std; int parent[6001]; int k; int f[6000][6000]; struct edge { int u,v,w; } edges[600

2011-11-17 18:50:21 276

转载 C/C++调用快排的模板

在进行C/C++编程的时候,C/C++的库函数中已经提供了快速排序法的函数qsort,我们只需要调用它就可以了。           qsort函数在头文件stdlib.h中。要使用qsort函数,就必须加#include(对C语言来说)或加入#include(对C++来说)。  下面是7种快排调用方法(注意下面的都是从小到大排序) 注意C语言是qsort C++是sort

2011-11-17 18:01:07 670

原创 poj j2031(几何+最小生成树)

计算各球心的距离,小于半径之和的算0,简单的几何计算+kruskal  注意double的快排调用时   wa了n次       #include #include #include #include #include using namespace std; int parent[10000]; int k; struct edge { int u,

2011-11-17 17:55:33 353

原创 poj 1259 Agri-Net

kruskal 基础题   #include #include #include #include #include using namespace std; int parent[5000]; int f[101][101]; int k; struct edge { int u,v,w; } edges[5000]; int compare(const void *a, co

2011-11-17 11:23:29 523

原创 hdu 4041 Eliminate Witches!

用栈去模拟 弹栈出栈就做完了 当时还没转c 用p写的   program aaa; var sl,n,m,i,j,k,tb,tc,x:longint; a:array[1..60000] of string; b,c,t:array[1..1000000] of longint; s,st:ansistring; flag:boolean;

2011-11-15 21:15:37 1071

原创 POJ 1861 Network

最小生成树是满足条件的一种树,并不是唯一解 调用qsort后数组从零开始计数。。。被这个搞死了     #include #include #include #include #include using namespace std; int parent[15001]; int k; struct edge { int u,v,w; } edges[15

2011-11-15 21:06:57 250

原创 最小生成树

Kruskal用并查集实在是太爽了   zoj 1542 / poj 1861:AC zoj 1718 / poj 2031:AC poj 2421: AC poj 1258: AC poj 3026: poj 2485:AC

2011-11-15 19:13:07 215

原创 POJ 2524 Ubiquitous Religions

题目大意:n个人,给定m对人宗教信仰相同,问最多有多少种宗教信仰。   和1611没多大区别 因为本题不需要考虑每个集合的个数,可以将parent负值简化,但我太懒了,不想改了。 #include #include int parent[50001]; int t; int findset(int x) { int tmp,s; s=x; while (paren

2011-11-15 17:13:39 220

原创 并查集

根据Slyar的博客 并查集三个基本函数:make find union 两个优化:find的时候进行状态压缩,union时将数量少的并到数量多的集合上   find 递归版本: int Find_Set(int x) { if (x != parent[x]) { parent[x] = Find_Set(parent[x]); } return parent[

2011-11-15 16:42:38 248

原创 POJ 1611 The Suspects

题目大意:给你几个同学的集合,0为传染源,和他同组的都被传染,问有多少人被传染   最简单的并查集 结果忘了 if (rr1==rr2) return RE了两次 #include #include int parent[30001]; int k; int findset(int x) { int tmp,s; s=x; while (parent[s]>=0

2011-11-15 16:37:53 214

空空如也

空空如也

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

TA关注的人

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