上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 42 下一页
摘要: 题意:N皇后方法:BFS+打表View Code 1 #include<stdio.h> 2 #include<string.h> 3 const int maxn = 21; 4 int sd[ maxn*2 ],c[ maxn ],md[ maxn*2 ]; 5 struct node{ 6 int r,c,flag; 7 }p,stack[ maxn*maxn ]; 8 int ans,n; 9 10 void bfs(){11 int top=-1;12 for( int i=n-1;i>=0;i-- ){13 stack[ ++top ].r... 阅读全文
posted @ 2013-02-01 22:05 xxx0624 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 1. 二分图的最小顶点覆盖(例hdu1150,poj3041) 在二分图中求最少的点,让每条边都至少和其中的一个点关联,这就是二分图的“最小顶点覆盖”。换句话说就是对于这也最小顶点集,原图中的每条边都至少有一个点在这个点集里面。 结论: 二分图的最小顶点覆盖数 = 二分图的最大匹配数2. DAG图的最小路径覆盖 (例hdu1151)用尽量少的不相交简单路径覆盖有向无环图(DAG)G的所有顶点,这就是DAG图的最小路径覆盖问题。结论:DAG图的最小路径覆盖数= 节点数(n)- 最大匹配数(m)3. 二分图的最大独立集(例hdu1068)最大独立集是指求一个二分图中最大的一个点集,该点集内的点互不 阅读全文
posted @ 2013-02-01 18:22 xxx0624 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个点,m条无向边。首先判断能否得到一个二分图(BFS),如果可以,则进行二分图匹配。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 const int maxn = 205; 8 const int maxm = 205*205; 9 struct node{10 int u,val,next;11 阅读全文
posted @ 2013-02-01 16:12 xxx0624 阅读(534) 评论(0) 推荐(0) 编辑
摘要: 题意:8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天?输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束.注意:每次消费的时候,都应该消费k的整数倍。View Code 1 #include<stdio.h> 2 int main(){ 3 int n,k; 4 while( scanf("%d%d",&n,&k)==2 && (n+k) ){ 5 int ans=0; 6 whi 阅读全文
posted @ 2013-02-01 11:34 xxx0624 阅读(364) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一些小猫的属性:体重和速度。然后求某些猫顺序的排列,使得体重上升,速度下降,这样的排列尽量长。DP+排序即:最长下降子序列View Code 1 #include<stdio.h> 2 #include<algorithm> 3 #include<string.h> 4 #include<stack> 5 using namespace std; 6 const int maxn = 1005; 7 struct node{ 8 int w,v,num; 9 }mouse[ maxn ];10 int dp[ maxn ];11 int 阅读全文
posted @ 2013-01-31 14:51 xxx0624 阅读(729) 评论(0) 推荐(0) 编辑
摘要: 还是prim预处理那些已经修好的路,变为0,即可。View Code 1 #include<stdio.h> 2 #include<string.h> 3 const int maxn = 103; 4 const int inf = 9999999; 5 struct node{ 6 int cost,is; 7 }mat[ maxn ][ maxn ]; 8 int dis[ maxn ],vis[ maxn ]; 9 int n,sum;10 11 int prim(){12 memset( vis,0,sizeof(vis));13 for( int i=1;. 阅读全文
posted @ 2013-01-30 22:23 xxx0624 阅读(310) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个坐标,求最小生成树。先将nike和apple之间的边加进来,并更新mat[nike][apple]=0,再贪心即可。或者:先把vis[ nike ]=vis[ apple ]=1,但是同时要更新dis[ i ]=min( mat[apple][i],mat[nike][i]);View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<algorithm> 5 using namespace std; 6 const int max 阅读全文
posted @ 2013-01-30 20:32 xxx0624 阅读(633) 评论(0) 推荐(0) 编辑
摘要: 预处理WA了N次。。。。。。。。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 1000005; 6 const int maxm = 1005; 7 int s[ maxn ],vis[ maxm ]; 8 int main(){ 9 memset( s,0,sizeof(s) );10 memset( vis,0,sizeof(vis) );11 int cnt=0;12 i 阅读全文
posted @ 2013-01-30 18:13 xxx0624 阅读(395) 评论(0) 推荐(0) 编辑
摘要: 简单模拟View Code 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 int main(){ 5 int a[ 1001 ]; 6 int cnt; 7 int n; 8 while( scanf("%d",&n)!=EOF ){ 9 for( int i=0;i<n;i++ )10 scanf("%d",&a[ i ]);11 cnt=0;12 for( int i=0;i<n-1;i++ ){1... 阅读全文
posted @ 2013-01-30 16:56 xxx0624 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 题意:从起点到终点,bfs不同的是对于图中的点,可能走多次,分别是在不同的时刻。myhash[ i ][ j ][ t%k ]=1:表示坐标( i,j )在 t%k 时刻走过,接下来再出现 t%k 就不用再走一次了。对于‘.’能入队,必须满足在该时刻没走过这个特点对于‘#’能入队,必须满足 该时刻没走过 且 该时刻 t%k==0 ;View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<stdlib.h> 5 #include<q 阅读全文
posted @ 2013-01-30 15:23 xxx0624 阅读(837) 评论(0) 推荐(0) 编辑
上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 42 下一页