2012年7月26日

摘要: hdu1372: http://acm.hdu.edu.cn/showproblem.php?pid=1372题意:一张8*8棋盘,横坐标用a~h表示,纵坐标用1~8表示,每对数据给出马的初始位置和目标位置,问需要多少步能到达code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int dx[]={-2,2,-1,1,-2,2,-1,1};int dy[]={1,-1,-2,-2,-1,1,2,2};int q[ 阅读全文
posted @ 2012-07-26 12:17 acmer-jun 阅读(166) 评论(0) 推荐(0) 编辑
摘要: hdu2579: http://acm.hdu.edu.cn/showproblem.php?pid=2579题意:“#”代表石头,如果走的步数是k的倍数,石头会消失,求最小时间(步数)code:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int inf=1<<29;char v[150][150];int q[150*150*150][2], 阅读全文
posted @ 2012-07-26 12:10 acmer-jun 阅读(162) 评论(0) 推荐(0) 编辑
摘要: hdu2102: http://acm.hdu.edu.cn/showproblem.php?pid=2102 题意:迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙 的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。code:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib 阅读全文
posted @ 2012-07-26 12:07 acmer-jun 阅读(180) 评论(0) 推荐(0) 编辑
摘要: hdu1728: http://acm.hdu.edu.cn/showproblem.php?pid=1728题意:求最少转弯数,开始时方向不定,所以第一次算不成转弯code:#include<iostream>#include<cstdio>#include<cstdlib>int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};int q[150*600][2],d[150][150][4];char v[150][150];const int inf=1<<29;int main(){ int i,j,m,n,x,y 阅读全文
posted @ 2012-07-26 12:02 acmer-jun 阅读(185) 评论(0) 推荐(0) 编辑
摘要: hdu1171: http://acm.hdu.edu.cn/showproblem.php?pid=1171题意:给定设备种类n,接下来输出n行,v[i]、m[i]表示有m[i]个价值为v[i]的设备,求将这些设备分为两部分,每部分的价值,要求两部分的价值相差最小。解法:混合背包,背包最大容量为总价值sum的一半s,要求价值尽量大,则f[s]和sum-f[s]即为答案。 code:#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int v[100],m[100 阅读全文
posted @ 2012-07-26 11:56 acmer-jun 阅读(149) 评论(0) 推荐(0) 编辑
摘要: hdu2191: http://acm.hdu.edu.cn/showproblem.php?pid=2191题意:容量为v的背包,有n种物品,每种物品时有限个的,有不同体积及价值,求最大价值解法:多重背包code:#include<iostream>#include<cstdio>#include<algorithm>int v[200],w[200],c[200],f[200];int max(int a,int b){ if(a>b) return a; else return b;}int main(){ int t,n,m,i,j,k,x.. 阅读全文
posted @ 2012-07-26 11:54 acmer-jun 阅读(202) 评论(0) 推荐(0) 编辑
摘要: hdu1712: http://acm.hdu.edu.cn/showproblem.php?pid=1712题意:输入课程数n和总天数m,再输入矩阵n*m,v[i][j]表示花费j天在课程i上得到价值为v[i][j]解法:分组背包问题:组数为n,总容量为m,每件物品费用为c[i]=j,价值为w[i]=v[i][j]code:#include<iostream>#include<cstdio>#include<cstdlib>int max(int a,int b){ if(a>b) return a; else return b;}int f[120 阅读全文
posted @ 2012-07-26 11:50 acmer-jun 阅读(154) 评论(0) 推荐(0) 编辑
摘要: hdu2602: http://acm.hdu.edu.cn/showproblem.php?pid=2602题意:有n个物品和容量为v的背包,每种物品只可取一个,且有不同价值及体积,求最大价值 解法:01背包code:#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int max(int a,int b){ if(a>b) return a; else return b;}int v[1010],w[1010],f[1010];int main(){ . 阅读全文
posted @ 2012-07-26 11:34 acmer-jun 阅读(206) 评论(0) 推荐(0) 编辑
摘要: hdu2546: http://acm.hdu.edu.cn/showproblem.php?pid=2546题意:输入n,表示有n种菜可购买,再输入n个数v[i],表示菜的价格,再输入m,表示卡上有m元,规定若卡上余额大于等于5则可购买任意价钱的物品(即使买后余额为负),否则不可购买任何物品,求最后卡上最小余额解法:01背包+贪心:最贵的物品肯定要被购买到,所以先选出来最后购买。先对除了最贵的物品外其余物品进行01背包处理,总容量为m-5,物品费用和价值都为w[i]。code:#include<iostream>#include<cstdio>#include< 阅读全文
posted @ 2012-07-26 10:19 acmer-jun 阅读(218) 评论(0) 推荐(0) 编辑

2012年7月25日

摘要: pku1178: http://poj.org/problem?id=1178题意:给出一行字符串,每对字母+数字表示棋盘上的一点,如A表示横坐标为1,B表示横坐标为2等,第一对表示王,只可上下左右移动,后面每一对表示一个马,走法跟象棋一样(没有算马脚),若马与王到了同一个格子,马可以带着王走,求总的最少需要多少步可使所有马和王汇集到一个格子里解法:floyd+3个枚举:先用floyd算出马在每个点到其他点的最小步数,再3层枚举:第一层枚举所有成员聚集点,第二层枚举马接王的点,第三层枚举求出马接王再到达聚集点中需要步数最小的马code:#include<iostream>#incl 阅读全文
posted @ 2012-07-25 22:07 acmer-jun 阅读(178) 评论(0) 推荐(0) 编辑

导航