View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;#define MIN(a,b) a<b?a:b#define INF 99999999#define MAX 5005int n,match[MAX];bool sx[MAX],sy[MAX];int lx[MAX],ly[MAX],map[MAX][MAX];char str[105][105];bool path(int u){ sx Read More
posted @ 2011-08-31 14:33 Because Of You Views(276) Comments(0) Diggs(0) Edit
讲一讲二分图的知识吧,自己以后也方便复习,(*^__^*) 嘻嘻……基本的一些定理的证明就不再讲了,书上、网上一大堆。。。。学习二分图,首先要知道什么是匹配,其次是最大匹配。最大匹配是关键,是很多情况的原型。学会最大匹配后,就是各种变形已经很多人总结好了,懒得写(*^__^*) 嘻嘻……如下:二分图是这样一个图,它的顶点可以分类两个集合X和Y,所有的边关联在两个顶点中,恰好一个属于集合X,另一个属于集合Y。最大匹配: 图中包含边数最多的匹配称为图的最大匹配。完美匹配:如果所有点都在匹配边上,称这个最大匹配是完美匹配。完全匹配:设X、Y是二分图G的两个部分。若X中每个结点都关联于匹配M中的一条边 Read More
posted @ 2011-08-31 13:46 Because Of You Views(882) Comments(0) Diggs(0) Edit
水水的,心头暖暖的~~~其实线段树就像trie树,解题的关键都存在于结构域中View Code #include<stdio.h>#include<string.h>#define R(x) x<<1|1#define L(x) x<<1#define MID(x,y) (x+y)>>1#define max(a,b) a>b?a:bconst int MAX=200010;struct {int s,l,r;}node[3*MAX];int c[MAX];int get_val(){ int ret(0); char c; w Read More
posted @ 2011-08-30 18:04 Because Of You Views(190) Comments(0) Diggs(0) Edit
View Code //第一次做线段树,不怎么会,试着模仿别人的写法,修修改改//继续努力!!!//初始状态全为1,x,y,z代表把x->y区间改为z#include<stdio.h>#include<string.h>const int MAX=100010;#define L(x) x<<1#define R(x) x<<1|1#define MID(x,y) (x+y)>>1struct {int color,l,r;}node[3*MAX]; void treeinit(){ memset(node,0,sizeof(n Read More
posted @ 2011-08-30 13:26 Because Of You Views(204) Comments(0) Diggs(1) Edit
设想一个矩形,左上角坐标为(x1,y1),右下角坐标为(x2,y2),现在我们对其利用二维树状数组进行区间求和sum(x2,y2)表示0,0--》x2,y2大矩形求和,sum(x1-1,y2)表示0,0->x1-1,y2求和sum(x2,y1-1)、sum(x1-1,y1-1)同理,sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1)即为所求矩形内的和跟一维其实一样,形变而神不变View Code #include<stdio.h>#include<string.h>int n;int c[1025][1025]; Read More
posted @ 2011-08-29 19:23 Because Of You Views(228) Comments(0) Diggs(0) Edit
#include <stdio.h>#include<string.h>#define MAXN 200int flag[MAXN][MAXN];int c[MAXN][MAXN];int lowbit(int i){ return i & -i;}void update(int x, int y, int color){ if (color == flag[x][y]) return ; flag[x][y] = color; int i, j; for (i = x; i <= MAXN; i += lowbit(i)) for (... Read More
posted @ 2011-08-29 16:40 Because Of You Views(474) Comments(0) Diggs(0) Edit
Color the ballTime Limit:5000MS Memory Limit:65536KTotal Submit:126 Accepted:53DescriptionN个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 < Read More
posted @ 2011-08-29 15:37 Because Of You Views(333) Comments(0) Diggs(0) Edit
离散化,但数据范围太大是所借用的利器,举个例子,有四个数99999999 1 123 1583 数据范围太大,而树状数组中的c数组开的范围是数据的范围,这时候就需要离散化,把四个数一次标号为1 2 3 4(即第一个数,第二个数。。。),按键值排序之后 依次为2 3 4 1(即从小到大排序为第二个数,第三个数。。。),所以,第二个数是最小的,即f[2]=1,f[3]=2,f[4]=3,f[1]=4,也就是把键值变为了1~n,相对大小还是不变的,即4 1 2 3。比如要求原来四个数的逆序数总和,现在就是求4 1 2 3的逆序数总和,大大节省了空间压力(树状数组的长度是数据范围)#include&l Read More
posted @ 2011-08-29 10:56 Because Of You Views(1074) Comments(0) Diggs(0) Edit
View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define MAX 32200 4 int c[MAX],level[MAX]; 5 int n; 6 int get_val() 7 { 8 int ret(0); 9 char c; 10 while((c=getchar())==''||c=='\n'||c=='\r'); 11 ret=c-'0'; 12 while((c=getchar())!=''&&c! Read More
posted @ 2011-08-28 19:01 Because Of You Views(304) Comments(1) Diggs(0) Edit
Matrix Chain MultiplicationTime Limit:1000MS Memory Limit:32768KTotal Submit:36 Accepted:26DescriptionMatrix multiplication problem is a typical example of dynamical programming.Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplication is Read More
posted @ 2011-08-28 13:05 Because Of You Views(378) Comments(0) Diggs(0) Edit