2012年9月3日
摘要: 大意:青蛙过河,河中有一定数量的石墩,求可能的最小步长过河。思路:将石墩距离起始点的距离排序,然后通过二分枚举求得是否存在一个m值(0~L),使得青蛙可以走过所有的石墩。如果存在且小于M,则记录满足条件的最小值。小结:二分枚举的题的特点都是是否单调连续,如果题目有这个特点的话,那么就可以考虑通过二分的思想来求解。CODE:#include<iostream>#include<stdio.h>#include<string.h>usingnamespacestd;constintSIZE=500010;intL,N,M;inta[SIZE];intcmp(co 阅读全文
posted @ 2012-09-03 18:38 有间博客 阅读(952) 评论(0) 推荐(0) 编辑
摘要: DFS练习。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=51;intsave[SIZE],b[SIZE];intans,n;voidprint(){for(inti=1;i<=6;i++){printf(i!=6?"%d":"%d\n",save[i]);}return;}voiddfs(intd){if(ans==6){print();return;}if(d>n)retu 阅读全文
posted @ 2012-09-03 10:09 有间博客 阅读(119) 评论(0) 推荐(0) 编辑