12 2012 档案
LightOJ 1400 Employment (Stable Marriage)
摘要:一道关于稳定婚姻的匹配题,算法的详细解释可以参考Matrix67的文章。下面是我根据算法思路写出来的代码:View Code 1 int comCan[N][N]; 2 int like[N], canLV[N][N]; 3 4 void input(int n) { 5 int x; 6 REP_1(i, n) { 7 REP_1(j, n) { 8 scanf("%d", &x); 9 comCan[i][j] = x - n;10 }11 }12 REP_1(i, n)...
阅读全文
poj 1077 Eight (bfs+康拓展开,A*&&IDA*算法)
摘要:http://poj.org/problem?id=1077 一道经典到不能再经典的搜做题,留到了今天,终于过了,好开心!!! 这题可以用很多中方法来做,例如bfs,dfs,A*,IDA*什么的。下面是我用普通bfs加上康拓展开来做的代码,800+ms险过的。View Code 1 bool used[N]; 2 char elem[10] = "12345678x"; 3 const char *end = "12345678x"; 4 5 int fac[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 36
阅读全文
USACO Shaping Regions(离散化)
摘要:记录一下我一直很怕做的一道离散化题。都卡了大半个月了,今天终于过了。这种离散化的题就一个恶心,不然早就啃过去了。代码如下:View Code 1 /* 2 ID: lyon.ly1 3 LANG: C++ 4 TASK: rect1 5 */ 6 7 #include <cstring> 8 #include <iomanip> 9 #include <cmath> 10 #include <cstdio> 11 #include <iostream> 12 #include <algorithm> 13 #include
阅读全文
poj 1062 昂贵的聘礼(dfs+剪枝)
摘要:http://poj.org/problem?id=1062 网上都说是dij,可是我想不到怎么dij。。。- -所以就只好暴力dfs+剪枝来做这题了。实践过,也就47ms,不会太长时间。这题注意的是,最高等级和最低等级的差不超过给定的值的判断。暴力搜索加上剪枝,剪枝的方法只需(1)跟目前找到的最小价格比较,判断是否继续找下去(2)判断是否曾经搜索了。通过代码:View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <iomanip> 5 #
阅读全文
poj 1011 Sticks(dfs+剪枝)
摘要:http://poj.org/problem?id=1011 回归基础,搞一下DFS+剪枝的题。 这题的代码打了两次,测了好多组数据才得到AC的代码。两次的代码都是因为返回的时候没有及时将used标记更新,而导致不停的WA。可是第一个代码写的太乱了,debug 漫天飞,于是就决定重新写了一遍。第二次打的时候思路清晰的许多,最后得到下面AC代码~View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <iomanip> 5 #include &
阅读全文
浙公网安备 33010602011771号