2012年7月25日

摘要: hdu1233: http://acm.hdu.edu.cn/showproblem.php?pid=1233题意:全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。解法:最小生成树:Kruskalcode:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int v[10000],k[10000],w[10000],r[ 阅读全文
posted @ 2012-07-25 17:21 acmer-jun 阅读(133) 评论(0) 推荐(0) 编辑
摘要: hdu1232: http://acm.hdu.edu.cn/showproblem.php?pid=1232题意:给几条边(可能重复给),求至少还需几条边能使各点直接或者间接联系解法:并查集:把已知的有联系的边减掉。code:#include<iostream>#include<cstdio>#include<cstdlib>int fa[1005],n,m;void solve(int a,int b){ for(int i=1;i<=n;i++) if(fa[i]==a) fa[i]=b;}int main(){ int ans,a,b; ... 阅读全文
posted @ 2012-07-25 17:17 acmer-jun 阅读(98) 评论(0) 推荐(0) 编辑
摘要: hud1875: http://acm.hdu.edu.cn/showproblem.php?pid=1875题意:给出c个点的坐标,若点与点之间的距离大于1000或小于10则不能建桥,建桥费用为每米100元,求使得所有点能相通的最小费用,若不能相通,则输出“oh!"。解法:最小生成树prim。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usin 阅读全文
posted @ 2012-07-25 17:05 acmer-jun 阅读(156) 评论(0) 推荐(0) 编辑
摘要: hdu1879: http://acm.hdu.edu.cn/showproblem.php?pid=1879题意:给出修建各条路的费用和是否已修(1为已修,0为未修),求要使所有点直接或者间接相连的最少费用解法:只需将已修的路的费用改为0,然后求最小生成树即可。法一:prim:code:#include<iostream>#include<cstdlib>#include<cstdlib>#include<algorithm>using namespace std;int v[110][110],sign[110];const int inf= 阅读全文
posted @ 2012-07-25 17:02 acmer-jun 阅读(137) 评论(0) 推荐(0) 编辑
摘要: hdu3342: http://acm.hdu.edu.cn/showproblem.php?pid=3342题意:判断是否有环,无环输出YES,有环输出NO解法:dfscode:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int v[150][150],c[150],n,m;bool dfs(int k){ c[k]=-1; for(int i=0;i<n;i++) { if(v[k][i]) { ... 阅读全文
posted @ 2012-07-25 16:55 acmer-jun 阅读(149) 评论(0) 推荐(0) 编辑
摘要: hdu2112: http://acm.hdu.edu.cn/showproblem.php?pid=2112题意:求最短路,输入的各个节点是用字符串表示的。解法:Dijkstra,将字符串转为编号,用int数组存入邻接矩阵code:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int inf=1<<29;char v[200][50];int 阅读全文
posted @ 2012-07-25 16:50 acmer-jun 阅读(158) 评论(0) 推荐(0) 编辑
摘要: hdu1195: http://acm.hdu.edu.cn/showproblem.php?pid=1195题意:求解密最少步骤:密码为四位数,每次操作可将一个数加一或减一(1减一变为9,9加一变为1),也可互换相邻数字,求最少需要多少操作数能解密解法:bfs:加一减一和交换位置都属于状态转移code:#include<iostream>#include<cstdio>#include<cstdlib>int q[1000*1000][4],v[4],key[4],dis[10][10][10][10],an1[4],bn1[4],cn1[4],dn1[4 阅读全文
posted @ 2012-07-25 16:44 acmer-jun 阅读(174) 评论(0) 推荐(0) 编辑
摘要: hdu1253: http://acm.hdu.edu.cn/showproblem.php?pid=1253题意:3层迷宫:一个A*B*C的立方体,可以被表示成A个B*C的矩阵,要从(0,0,0)到(A-1,B-1,C-1),若时间小于t,输出时间,否则输出-1.解法:bfs:开三维数组d[i][j][k]表示在第k个矩阵的点(i,j)上,队列要进点和k。code:#include<iostream>#include<cstdio>#include<cstdlib>int d[60][60][60];char v[60][60][120];struct a 阅读全文
posted @ 2012-07-25 16:40 acmer-jun 阅读(153) 评论(0) 推荐(0) 编辑
摘要: hdu1072: http://acm.hdu.edu.cn/showproblem.php?pid=1072题意:0代表墙,1代表空地,2代表始点,3代表终点,4代码时间重置,炸弹限时6s,每走一步耗时1s,如果到达4可重置为6s,求最少逃脱时间,逃脱不了输出-1解法:bfs:开三维数组d[i][j][k]表示到达(i,j)点时剩余时间为k,此时的最优值,队列开二维q[rear][0]进点,q[rear][1]进剩余时间code:#include<iostream>#include<cstdio>#include<cstdlib>int d[10][10] 阅读全文
posted @ 2012-07-25 16:20 acmer-jun 阅读(168) 评论(0) 推荐(0) 编辑
摘要: hdu2151: http://acm.hdu.edu.cn/showproblem.php?pid=2151题意:给出n棵树、p、t分别表示虫的起始树和终点树,m为m分钟后到达t,求最多有多少中走法能从p到t,每次移动只能移向左或者右边的树解法:dp:dp[i][j]表示到达第j棵树,前i分钟的走法数,则转移方程为:dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1],注意初始化。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm> 阅读全文
posted @ 2012-07-25 15:59 acmer-jun 阅读(142) 评论(0) 推荐(0) 编辑

导航