• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
tmeteorj
Nothing is so big that it is impossible to get over, and hurt only serves to make us stronger. 没有什么事是大到无法战胜的,痛苦也只会让我们变得更加坚强。
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

随笔分类 -  ACM 图论

上一页 1 2

 
POJ 1192
摘要:题意:题目叙述很长,但很简单,其实如果是英文题倒还可以狠狠的恶心一下人的= =!就是给一个无向树,求最大权子树题解:树形dp,dp[i][0]代表不要第i个点时以i为根的子树的最大价值,dp[i][1]代表必须要i时以i为根的子树的最大值。于是dp[i][0]=max(dp[i][0],dp[j][0],dp[j][1]),j为i能到的点,dp[i][1]=val+sum(max(dp[j][1],0)),即取所有权值为正的i的子树与它相连,注意必须是dp[i][1],因为要保证树最后的连通性。View Code 1 #include<cstdio> 2 #include<c 阅读全文
posted @ 2012-09-18 20:29 tmeteorj 阅读(371) 评论(2) 推荐(0)
POJ 2139
摘要:题意:给定牛的关系图,求其中一头牛与其他牛关系路程之和最小,然后输出这数乘以一百在除以n-1,虽然貌似题目没说,但是是向下取整= =!题解:flyod最短路,枚举找最小View Code 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int d[400][400]; 6 int main() 7 { 8 int n,m; 9 while(scanf("%d%d",&n,&m)!=EOF)10 {11 阅读全文
posted @ 2012-09-16 18:22 tmeteorj 阅读(534) 评论(0) 推荐(0)
POJ 3275
摘要:题意:将n头牛产奶速度又快到慢排序,已经比较了m对牛,问还至少需要多少次比较。题解:n头牛如果排序完成,应该有C(n,2)关系已知,即任意两头牛的速度都知道了。然后可以从已经比较了的m对牛中算出可以推导出多少对牛已经知道了,推导方法可以参考floyd最短路,然后用C(n,2)减去它就是答案。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int head[2][1005],nc[2]; 6 struct Edge 7 阅读全文
posted @ 2012-09-15 20:21 tmeteorj 阅读(408) 评论(0) 推荐(0)
POJ 3680
摘要:题意:给定n个带权开区间,选择其中一些使得权值最大并且区间重叠层数不超过k。题解:最小费用流,区间有两百个,可以用左边的点发出一条到右边的点的边,容量为1,费用为负的权值。然后从左往右将依次将相邻的两个点都连起来,权值为0,容量为k,也就是说,如果选了这个区间,就会从费用为负数的边流过去,否则,就是从这个费用为0的边流过去。然后建立一个虚拟源点与最左边的点相连,权值为0,容量为k,这样就保证了重叠数之多为k,因为增广路上所经过的区间必定是不重合的,而流量只有k,所以满足题意。View Code 1 #include<cstdio> 2 #include<cstring> 阅读全文
posted @ 2012-09-14 19:18 tmeteorj 阅读(1329) 评论(0) 推荐(0)
POJ 1815
摘要:求字典序最小的最小割,首先,对于每一个不是源点和汇点,拆成两个点,有一条容量为一的边。求一次最小割后,针对每一个结点,按照字典序枚举若是删了它与它映射过去的另一个点之间的边是否会使得最小割变小,是则必须删它,否则,不用。本来应该dfs求出S,T集合的来降低复杂度的(判断删去一条边是否会使得最小割变小),但是这道题点数边数都很小,直接暴力就行了。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=5 阅读全文
posted @ 2012-09-13 19:46 tmeteorj 阅读(301) 评论(0) 推荐(0)
HDOJ 4276
摘要:先将1到n的路径上的点进行缩点,总时间减去该路径长度,然后这道题就和ZOJ 3626一模一样了,也就是,树形DP。。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int head[200],nc,dp[200][600],v[200]; 6 struct edge 7 { 8 int to,cost,next; 9 }edge[1000]; 10 struct data 11 { 12 int a,b,c; 13 阅读全文
posted @ 2012-09-08 18:20 tmeteorj 阅读(205) 评论(0) 推荐(0)
POJ 2688
摘要:找一条哈密顿路,爆搜完事#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int path[20][20];bool mark[30][30];int map[30][30];char ss[30][30];struct data{ int x,y,step; data(){}; data(int _x,int _y,int _step){x=_x;y=_y;step=_step;}};data po[15];int dr[ 阅读全文
posted @ 2012-09-08 11:27 tmeteorj 阅读(193) 评论(0) 推荐(0)
POJ 1270
摘要:dfs输出原图所有拓扑序就行了。#include<cstdio>#include<cstring>#include<cctype>using namespace std;int d[30],head[30],nc,n;struct edge{ int to,next;}edge[200];void add(int a,int b){ edge[nc].to=b;edge[nc].next=head[a];head[a]=nc++;}char ans[30];void dfs(int k){ if(k==n) { puts(ans); retu... 阅读全文
posted @ 2012-09-05 20:49 tmeteorj 阅读(369) 评论(0) 推荐(0)
POJ 2584
摘要:裸的最大流View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=2000,M=10000; 6 const int inff=1<<29; 7 int head[N],nc; 8 struct edge 9 { 10 int x,y,next; 11 int cap; 12 } edge[M*3]; 13 void add(int x,int y,int cap) 14 { 15 edg 阅读全文
posted @ 2012-09-05 19:10 tmeteorj 阅读(168) 评论(0) 推荐(0)
POJ 2225
摘要:三维最短路View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 struct data 7 { 8 int x,y,z; 9 bool operator==(const data &ne)const10 {11 return x==ne.x&&y==ne.y&&z==ne.z;12 }13 data(){}14 data(int _x, 阅读全文
posted @ 2012-09-04 21:30 tmeteorj 阅读(220) 评论(0) 推荐(0)
POJ 2110
摘要:O(n^3log(n))47MS水过,枚举高度差log(n),枚举最低高度n,dfs一遍n^2View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 bool mark[105][105]; 6 int map[105][105]; 7 int n; 8 bool dfs(int x,int y,int mmin,int len) 9 {10 mark[x][y]=true;11 if(x==n&&y==n) 阅读全文
posted @ 2012-09-03 20:15 tmeteorj 阅读(199) 评论(0) 推荐(0)
POJ 3436
摘要:虽然一次秒过六级,但还是觉得这种冗长的题目非常蛋疼~3进制位压缩以进行判断是否有边,接着就是一次最大流,判断最后经过了哪些边只用考虑拆点后右边的点发出去的通往左边的点的那些边里初始流量减去现在流量是否等于0即可。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=200,M=20000; 6 const int inff=10000000; 7 int head[N],nc; 8 struct e 阅读全文
posted @ 2012-09-02 12:13 tmeteorj 阅读(217) 评论(0) 推荐(0)
POJ 3498
摘要:拆点+最大流,对与拆开的点建立容量为最多跳几次的边,在建立源点到每个点的边,容量为那有多少只企鹅,最后让互相能到的点建立边。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=800,M=100000; 6 const int inff=1<<29; 7 const double eps=1e-8; 8 int head[N],nc; 9 struct edge 10 { 11 int 阅读全文
posted @ 2012-09-02 10:46 tmeteorj 阅读(146) 评论(0) 推荐(0)
POJ 2570
摘要:可以看成floyd,用bool变量标记公司View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<set> 4 using namespace std; 5 bool ss[300][300][30]; 6 void floyd(int n) 7 { 8 for(int k=1;k<=n;k++) 9 {10 for(int i=1;i<=n;i++)11 {12 if(ss[i][k][26])13 {14 ... 阅读全文
posted @ 2012-09-02 09:33 tmeteorj 阅读(178) 评论(0) 推荐(0)
POJ 3310
摘要:题目给出的判断条件有三:无环,连通,存在一条链囊括所有的的结点或者邻接所有顶点。前两条件就不说了,第三个其实就是看一个结点它的儿子子树之中是否有大于2棵结点数超过1,另外,如果恰有2棵,还需看父亲祖辈是否有超过一个的结点。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=105,M=305; 6 int head[N],nc; 7 struct edge 8 { 9 int to,next;10 阅读全文
posted @ 2012-08-30 16:42 tmeteorj 阅读(274) 评论(0) 推荐(0)
POJ 3189
摘要:被这题坑了多次,就一 二分+二分图多重匹配。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=1500,M=50000; 6 int head[N],nc; 7 struct edge 8 { 9 int x,y,next; 10 } edge[M]; 11 void add(int x,int y) 12 { 13 edge[nc].x=x; 14 edge[nc].y=y; 15 ... 阅读全文
posted @ 2012-08-30 16:09 tmeteorj 阅读(262) 评论(0) 推荐(0)
POJ 3411
摘要:用mark[i][st]记录到达i点时到所有点情况为st时的最小花费,向下一步走的时候可以查看要到的点需要经过的中间点是否在st中,然后用优先队列+最短路便可以解决了。#include<cstdio>#include<cstring>#include<queue>using namespace std;const int N=12;int head[N],nc;struct edge{ int to,by,c1,c2,nxt;}edge[N*3];void add(int a,int b,int c,int c1,int c2){ edge[nc].to=b 阅读全文
posted @ 2012-08-30 14:17 tmeteorj 阅读(245) 评论(0) 推荐(0)
POJ 1985
摘要:最长链,两遍heap+dijiska#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int N=40005;int head[N],nc;struct edge{ int to,cost,next;}edge[N*3];void add(int a,int b,int c){ edge[nc].to=b;edge[nc].next=head[a];edge[nc].cost=c;head[a]=nc++; ed 阅读全文
posted @ 2012-08-30 11:17 tmeteorj 阅读(304) 评论(0) 推荐(0)
POJ 3204
摘要:求一次最小割,dfs一遍,然后对每一个满流且是正向边的做一次检查,如果这条边的终点能够到达汇点,则说明可以拓宽这条边来改进网络。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=1000,M=10000; 6 const int inff=1<<29; 7 int head[N],nc; 8 struct edge 9 { 10 int x,y,next; 11 int cap; 1 阅读全文
posted @ 2012-08-29 19:37 tmeteorj 阅读(201) 评论(0) 推荐(0)
 

上一页 1 2

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3