原体链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308区间合并代码: #include"stdio.h" #include"string.h" #include"stdlib.h" struct SegTree { int l,r,mid; int l_max,r_max,m_max; }T[400000]; int a[100011]; void pushup(int k) { int l_l,r_l; ... Read More
posted @ 2013-06-04 20:37 supersnow0622 Views(135) Comments(0) Diggs(0) Edit
原体链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698线段树成段更新代码:#include <stdio.h>#define max 111111#define lson l,mid,index<<1#define rson mid+1,r,index<<1|1int mark[max<<2];int value[max<<2];void sum(int index){ value[index]=value[index<<1]+value[index<<1|1]; Read More
posted @ 2013-06-04 20:33 supersnow0622 Views(149) Comments(0) Diggs(0) Edit
原体链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024【问题描述】----最大M子段和问题给定由 n个整数(可能为负整数)组成的序列a1,a2,a3,……,an,以及一个正整数 m,要求确定序列 a1,a2,a3,……,an的 m个不相交子段,使这m个子段的总和达到最大,求出最大和。 题解:转自http://www.cnblogs.com/peng-come-on/archive/2012/01/15/2322715.html动态规划的思想。1.基本思路: 首先,定义数组num[n],dp[m][n]. num[n]用来存储n个整数组成的序列.. Read More
posted @ 2013-06-03 17:54 supersnow0622 Views(151) Comments(0) Diggs(0) Edit
原体链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045解题思路:用dfs进行搜索 示例:. . . 搜索第一个点,可以放置碉堡,标记为'O',接下来的点都不能放置,然后回溯到第一个点,此时第一个点为'.',在搜索第二个点,放置碉堡,第三个点不能放, . X X 标记为'O',第四个点可放置,标记为'O',继续往后搜索时,其他顶点都不能放置,回溯到第四个顶点,此时第四个顶点为'.',继续往后搜索,搜到第七个顶点时可放置碉堡... . X X代码:#include< Read More
posted @ 2013-05-30 15:23 supersnow0622 Views(146) Comments(0) Diggs(0) Edit
原题链接:http://poj.org/problem?id=1459代码:#include<stdio.h>#include<iostream>#include<queue>#include<memory.h>using namespace std;const int MAX=200+10;int cap[MAX][MAX];//记录每条路的容量/*EdmondsKarp(int cap[10001][10001],int s,int t) 函数说明:cap是记录每条路经容量的二维数组 s是源的下标 t是汇的下标 n是节点的数量*/void E Read More
posted @ 2013-05-28 20:00 supersnow0622 Views(141) Comments(0) Diggs(0) Edit
原体链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532代码:#include<iostream>#include<memory.h>#include<queue>using namespace std;int min(int a,int b){ return a<b?a:b;}int getMax(int c[201][201],int nodenum){ int flow[201][201],max=0;//记录每条路的实际运输量 int a[201],pre[201];//min记录到达此点的最小运输 Read More
posted @ 2013-05-28 19:59 supersnow0622 Views(128) Comments(0) Diggs(0) Edit
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829代码:#include <stdio.h>#include<memory.h>using namespace std;int father[2001],child[2001],sex[2001];int findfather(int x){ while(x!=father[x]) x=father[x]; return x;}void unitnode(int x,int y){ x=findfather(x); y=findfather(y); if(x==y) re Read More
posted @ 2013-05-27 10:19 supersnow0622 Views(193) Comments(0) Diggs(0) Edit
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232代码:#include<iostream>using namespace std;int father[1001];int findfather(int x){ while(father[x]!=x)//如果x的父节点不是他本身,证明x不是根 x=father[x]; return x;}void unitnode(int x,int y){ int f1=findfather(x); int f2=findfather(y); if(f1!=f2) fathe... Read More
posted @ 2013-05-27 10:17 supersnow0622 Views(187) Comments(0) Diggs(0) Edit
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312代码:#include <iostream>#include<queue>using namespace std;char map[21][21];int row,col;int startX,startY;int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};struct Node{ int x,y;};Node N,P; int num;void bfs(){ queue<Node> q; N.x=startX; N.y=s Read More
posted @ 2013-05-24 21:51 supersnow0622 Views(150) Comments(0) Diggs(0) Edit
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253代码:#include <stdio.h>#include<queue>#include<memory.h>using namespace std;int map[51][51][51];int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};int x,y,z,t;struct Node{ int xx,yy,zz,usedtime;};Node N,P;bool judge;v Read More
posted @ 2013-05-24 21:47 supersnow0622 Views(186) Comments(0) Diggs(0) Edit