POJ 2251 Dungeon Master
摘要:这道题本来不难,但是写的纠结。三维广搜,只有六个方向,有一段时间没写结构体,发现很不熟练。/*Accepted 612K 16MS C++ 2362B 2012-07-23 17:48:55*/#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;const int MAXN = 50;const int dx[] = { 1, -1, 0, 0, 0, 0};const int dy[] = { 0, 0, 1, -1, 0, 0
阅读全文
posted @
2012-07-23 17:52
找回失去的
阅读(170)
推荐(0)
POJ 1141 Brackets Sequence
摘要:括号序列,刘汝佳黑书上的经典例题。但是这道题要输出我们最后得到的添加括号最少的序列,输出序列确实很麻烦,参考了题解,才勉勉强强写出来,以后还得把这道题敲一遍。/*Accepted 288K 32MS C++ 1862B 2012-07-23 11:46:07*/#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;#define o -2#define lr -3const int MAXN = 105;int f[MAXN
阅读全文
posted @
2012-07-23 11:53
找回失去的
阅读(235)
推荐(0)
POJ 1080 Human Gene Functions
摘要:现在给出两个碱基序列,可以在两个串间插入‘-’即空白,求两串的最大相似度。最长公共子序列的变形状态转移方程:f[i][j] = Max( f[i - 1][j] + score[dna(a[i])][4], f[i][j - 1] + score[4][dna(b[j])], f[i - 1][j - 1] + score[dna(a[i])][dna(b[j])])/*Accepted 216K 0MS C++ 1329B 2012-07-23 09:19:46*/#include<cstdio>#include<cstring>#include<algorit
阅读全文
posted @
2012-07-23 09:37
找回失去的
阅读(162)
推荐(0)
POJ 2115 C Looooops
摘要:被虐得很惨的一道题,WA了无数次,根据题意推出C*x+(2^k)*y=B-A,用拓展欧几里德求出x的最小值。如果无解则是死循环!/*Accepted 164K 0MS C++ 882B 2012-07-19 12:03:12*/#include<cstdio>#include<cstring>#include<cstdlib>#define LL long longLL extgcd( LL a, LL b, LL &x, LL &y){ if( b == 0) { x = 1; y = 0; return a;} LL d = extgcd
阅读全文
posted @
2012-07-19 12:10
找回失去的
阅读(209)
推荐(0)
COJ 1030 素数槽
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1030用线性筛素数果然快多了。#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 1300000bool is_p[MAXN];void calc(){ for( int i = 1; i < MAXN; i ++) is_p[i] = true; is_p[1] = false; for( int i = 2; i < MAXN; i ++) { if( !is_p[i..
阅读全文
posted @
2012-05-26 22:35
找回失去的
阅读(533)
推荐(0)
POJ 3278 Catch That Cow
摘要:一维的广搜,从当前点到下个点有三种选择,然后求步数即可。用了STL的队列,然后忘了加using namespace std,检查浪费了时间。/*Accepted 860K 110MS C++ 640B 2012-05-26 20:44:59 */#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;#define MAXN 100005int d[MAXN], N, K;void bfs(){ queue<int> q;
阅读全文
posted @
2012-05-26 20:51
找回失去的
阅读(181)
推荐(0)
POJ 2488 A Knight's Journey
摘要:http://poj.org/problem?id=2488 好久没写回溯,题目要求骑士遍历全图,不能实现就输出“impossible”,首先遍历的方向要选好,字典序,其次判断遍历了全图的条件就是走了p*q-1步。初始点选取A1即可。/*Accepted 168K 16MS C++ 1267B 2012-07-23 15:35:53*/#include<cstdio>#include<cstring>#include<cstdlib>const int MAXN = 30;const int dx[] = {-2, -2, -1, -1, 1, 1, 2,
阅读全文
posted @
2012-05-26 20:23
找回失去的
阅读(172)
推荐(0)
POJ 2785 4 Values whose Sum is 0
摘要:用hash写了一遍,hash的空间复杂度不是盖的/*Accepted 176460K 3907MS C++ 1006B 2012-05-25 09:13:41 */#include<cstdio>#include<cstring>#include<cstdlib>#define cal(x) ( (x + (1 << 29 | 1) * M) % MAX)#define LL __int64const int MAX = 20000001;const int M = 17531753;const int MAXN = 4005;int hash[
阅读全文
posted @
2012-05-25 09:15
找回失去的
阅读(210)
推荐(0)
POJ 2785 4 Values whose Sum is 0
摘要:枚举左边两个数的和以及右边两个数的和,用二分查找将其配对并计数。Hash的方法晚点再写。/*Accepted 49208K 5188MS C++ 1146B 2012-05-04 23:56:30 */#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;#define MAXN 4005/*int cmp( const void *_p, const void *_q){ int *p = ( int *)_p; int
阅读全文
posted @
2012-05-05 00:00
找回失去的
阅读(339)
推荐(0)
POJ 1316 Self Numbers
摘要:按照题目的要求我们将有generator的数标记,然后输出没标记的即可。/*Accepted 168K 16MS C++ 412B 2012-05-04 22:50:01 */#include<cstdio>#include<cstring>#include<cstdlib>bool is[10005];int main(){ int i, j, res, sum; memset( is, false, sizeof is); for( i = 1; i <= 10000; i ++) { if( !is[i]) { p...
阅读全文
posted @
2012-05-04 22:58
找回失去的
阅读(171)
推荐(0)
POJ 1046 Color Me Less
摘要:先输入16个像素点,然后每输入一个像素点,输出与其最相近的像素点。/* Accepted 176K 0MS C++ 664B 2012-05-04 22:34:22 */#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#define MAXN 20int A[MAXN], B[MAXN], C[MAXN];int a, b, c;int k;int main(){ for( int i = 0; i < 16; i ++) scanf( "%d%d%
阅读全文
posted @
2012-05-04 22:43
找回失去的
阅读(195)
推荐(0)
三道水题
摘要:做了三道水题,练手。水题也要细心POJ 1004:/*Accepted 180K 0MS C++ 187B 2012-04-26 16:48:20 */#include<cstdio>double a, sum;int main(){ sum = 0; for( int i = 0; i < 12; i ++) { scanf( "%lf", &a); sum += a; } printf( "$%.2lf\n", sum / 12); return 0;}POJ 2027/*Accepted 164K 0MS C++ 223B
阅读全文
posted @
2012-04-26 17:14
找回失去的
阅读(198)
推荐(0)
POJ 1631 Bridging signals
摘要:这道题之前做过。左边线柱是升序排列的,所以要找右边线柱的最长升序列,因为最大范围是N = 40000,所以只能用o(nlogn)的写法。/*Accepted 296K 125MS C++ 581B 2012-04-22 19:00:19 */#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 40005int s[MAXN], top, t, n;int main(){ int T; scanf( "%d", &T); while( T --) { scan
阅读全文
posted @
2012-04-22 19:05
找回失去的
阅读(186)
推荐(0)
POJ 1887 Testing the CATCHER
摘要:这道题是求一个最长下降子序列,o(nlogn)的算法也不难写,仿照最长升序子序列的写法,还好二分没写成死循环。这题输入比较坑爹,每组测试以-1结尾,结束所有测试也是-1,然后要求没两组之间有空行,在测试的时候看到的是输入每组第一个数才空行,这里浪费了不少时间…/*Accepted 168K 0MS C++ 627B 2012-04-22 18:33:00 */#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 32900int a[MAXN], t;int main(){ int to
阅读全文
posted @
2012-04-22 18:40
找回失去的
阅读(225)
推荐(0)
POJ 2192 Zipper
摘要:判断a的前i个字母和b的前j个字母能否构成 c的前 i + j个字母,递推,注意数组开大些,205居然会wa。/*Accepted 220K 0MS C++ 911B 2012-04-22 10:42:42 */#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 255bool match[MAXN][MAXN];char a[MAXN], b[MAXN], c[MAXN << 1];int la, lb, lc;void dp(){ int i, j; la = strl
阅读全文
posted @
2012-04-22 11:03
找回失去的
阅读(217)
推荐(0)
POJ 3264 Charm Bracelet
摘要:01背包,还好没忘记是怎么写的!/*Accepted 240K 266MS C++ 563B 2012-04-22 09:13:42 */#include<cstdio>#include<cstdlib>#include<cstring>#define MAXN 3407#define MAXM 12900#define max( a, b) ( a > b ? a : b)int w[MAXN], d[MAXN];int f[MAXM];int N, M;void init(){ for( int i = 1; i <= N; i ++) sc
阅读全文
posted @
2012-04-22 09:16
找回失去的
阅读(170)
推荐(0)
POJ 2240 Arbitrage
摘要:要套现的前提是有一种货币经过几次交换能是其到其本身的汇率大于1。就转换成了求任一货币到其自身的汇率,不过要通过其他货币才能转换到自身,所以用floyd算法,求出所有货币到其他货币或者自身的最大汇率。这里的floyd计算时是汇率相乘取最大值,这也是与普通floyd的区别。字符串的处理是本题设置的一个考点吧,不过还好对于这个已经无压力了。/*Accepted 192K 47MS C++ 1074B 2012-04-14 12:57:03 */#include<cstdio>#include<cstring>#include<cstdlib>const int M
阅读全文
posted @
2012-04-14 13:01
找回失去的
阅读(593)
推荐(0)
POJ 1258 Agri-Net
摘要:很普通的一道关于最小生成树的题,回顾了下kruskal算法的写法。/*Accepted 332K 16MS C++ 987B 2012-07-23 23:03:38 */#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int MAXN = 105;int p[MAXN], r[MAXN * MAXN], u[MAXN * MAXN], v[MAXN * MAXN], w[MAXN * MAXN];int n
阅读全文
posted @
2012-04-14 10:17
找回失去的
阅读(166)
推荐(0)
POJ 3253 Fence Repair
摘要:这道题类似于哈夫曼树,每次切付出的代价等于长度,所以我们要将长的先截出来。而题目是给出N截,以及每截的长度。所以我们每次加上短的,使总代价最少。学会了优先级队列的STL写法。/*Accepted 348K 32MS C++ 644B 2012-07-30 16:32:44*/#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;typedef long long LL;int N;LL calc(){ LL ans; int len
阅读全文
posted @
2012-04-13 19:15
找回失去的
阅读(135)
推荐(0)
POJ 1159 Palindrome
摘要:#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 5005#define max(a, b) ( a > b ? a : b)short f[MAXN][MAXN], len;char a[MAXN], b[MAXN];void rev(){ for( int i = len, j = 1; i >= 1; i --, j ++) { b[j] = a[i]; }}void dp(){ memset( f, 0, sizeof f); for( int i = 1; i
阅读全文
posted @
2012-04-11 12:43
找回失去的
阅读(137)
推荐(0)