上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 17 下一页

2012年4月3日

UVa 348 - Optimal Array Multiplication Sequence

摘要: 这道题是矩阵链,本来想照着书写的,L不在,于是自己想了想,试了试,没想到还真写出来了。。看来最难的不是题,而是如何克服畏惧的心(The only thing you have to fear, is fear itself.)。。记忆化搜索,打印那里想来想去不知道怎么把几种情况统一起来,也忘了书上怎么处理的。 1 /* 348 - Optimal Array Multiplication Sequence */ 2 # include <stdio.h> 3 # include <memory.h> 4 5 typedef struct { 6 int r; 7 int 阅读全文

posted @ 2012-04-03 11:11 getgoing 阅读(218) 评论(0) 推荐(0) 编辑

UVa 562 - Dividing coins

摘要: 用half替代sum>>1后通过了,不明原因。 1 /* 562 - Dividing coins */ 2 # include <stdio.h> 3 # include <memory.h> 4 5 int v[105]; 6 int f[50050/2]; 7 8 int main() 9 {10 int n, m, i, sum, j, half;11 12 scanf("%d", &n);13 while (n--)14 {15 scanf("%d", &m);16 for (sum = 0, 阅读全文

posted @ 2012-04-03 09:53 getgoing 阅读(215) 评论(0) 推荐(0) 编辑

2012年4月2日

c++比c快?一道字符串题目

摘要: 题目是这样的:求通过添加字将一个字符串变为回文字符串所需最少的添加次数。解法:求出该字符串与反串的最大公共子序列的长度k,那么字符串的长度n减去k就是所求值。为了不超出内存限制,使用了类似滚动数组的方法。问题在这里,C程序和改写后的C++程序(只改写了头文件,添加了一句using namespace std;),而被判运行时差足有3s,有图为证:可能与测试数据和OJ的评判系统有关,但我想肯定也和这两种语言某种方面的差异有关,在此请教路过的同学,谢谢!附:原题链接:1097 PalindromeC代码 1 # include <stdio.h> 2 # include <str 阅读全文

posted @ 2012-04-02 22:22 getgoing 阅读(567) 评论(0) 推荐(0) 编辑

UVa 357 - Let Me Count The Ways

摘要: 又是硬币型的。。虽然通过了,还有几个疑问:1. 题目中说 The input will consist of a set of numbers between 0 and 30000 inclusive, one per line in the input file. , 难道不包括30000吗? 输入30000时AC的程序结果是负值(将long long int 改为unsigned long long int可以解决)。2. 使用dev c++输出时出现错误: There are 6 ways to produce 0 cents change. There are 4 ways t... 阅读全文

posted @ 2012-04-02 13:18 getgoing 阅读(351) 评论(0) 推荐(0) 编辑

UVa 147 - Dollars

摘要: 无数次WA换来一次AC,只因没有使用long long int。。。 1 # include <stdio.h> 2 # include <math.h> 3 4 const int coin[] = {0,5,10,20,50,100,200,500,1000,2000,5000,10000}; 5 6 long long int f[6010][12]; 7 8 long long int dp(int m, int i); 9 10 int main()11 {12 double c;13 14 while (1)15 {16 sca... 阅读全文

posted @ 2012-04-02 11:47 getgoing 阅读(288) 评论(0) 推荐(0) 编辑

UVa 10192 - Vacation

摘要: 又是lcs,所幸 7min AC了。 1 # include <stdio.h> 2 # include <string.h> 3 4 int len; 5 int x[2]; 6 char s1[105]; 7 char s2[105]; 8 int ans[105*105]; 9 10 int lcs(int *x);11 12 int main()13 {14 int cnt;15 16 cnt = 0;17 while (NULL != gets(s1))18 {19 if (s1[0] == '#') break;20... 阅读全文

posted @ 2012-04-02 10:22 getgoing 阅读(380) 评论(0) 推荐(0) 编辑

UVa 10066 - The Twin Towers

摘要: 一看就知道是lcs,10分钟敲好了代码,通过示例,一提交MLE,明白了没有保存中间结果;再次提交,打开邮箱,一直F5,等了很长时间没反应,难道又MLE了?结果回到题目页面,发现了下面这句话:You have to select a programming language.。。。再次提交WA:没有把ans[]初始化为-1;最终花了25分钟才AC了,教训啊! 1 # include <stdio.h> 2 # include <memory.h> 3 4 int N1, N2; 5 int x[2]; 6 int s1[101]; 7 int s2[101]; 8 int 阅读全文

posted @ 2012-04-02 10:06 getgoing 阅读(552) 评论(0) 推荐(0) 编辑

UVa 10131 - Is Bigger Smarter?

摘要: DAG最大路径;AC后我搜了搜,有几个是理解为最大下降子列(我开始也这么想的),但是作为dp的练习题,就化为DAG了,复杂度当然高了,但是没超时。 1 # include <stdio.h> 2 3 int n; 4 int w[1000]; 5 int s[1000]; 6 int d[1000]; 7 int g[1000][1000]; 8 9 int dp(int i);10 void print_list(int i);11 12 int main()13 {14 int i, j, maxl, k;15 16 n = 1;17 while (~s... 阅读全文

posted @ 2012-04-02 09:30 getgoing 阅读(377) 评论(0) 推荐(0) 编辑

UVa 116 - Unidirectional TSP

摘要: 简单的动态规划(递推),要能够打印最小权值对应的最小字典序路径;MIN 定义中‘<’写成了‘>’导致一次WA。。另外求最小权值对应的最小下标那里写的很乱。# include <stdio.h># define MIN(X,Y) ((X)<(Y) ? (X):(Y))int f[12][105];int p[12][105];int col, row;int main(){ int i, j, ans, t, x; while (~scanf("%d%d", &row, &col)) { for (i = 0; i < ro 阅读全文

posted @ 2012-04-02 00:50 getgoing 阅读(1311) 评论(0) 推荐(0) 编辑

2012年4月1日

UVa 10003 - Cutting Sticks

摘要: 记忆化搜索;需要判断当前状态是否被更新。# include <stdio.h># include <string.h># define INF 20000int l, n;int s[54];int f[55][55];int dp(int i, int j);int main(){ int i, j; while (1) { scanf("%d", &l); if (l == 0) break; scanf("%d", &n); if (l == 0) break; for (i = 1;... 阅读全文

posted @ 2012-04-01 23:38 getgoing 阅读(257) 评论(0) 推荐(0) 编辑

csuoj 1215 稳定排序

摘要: 经过一位大牛的指点,放弃了使用分治的念头,看来快排还是很灵活的。 1 # include <stdio.h> 2 # include <stdlib.h> 3 4 # define MAXN 100005 5 6 typedef struct { 7 int X, Y; 8 int I; 9 }data;10 11 data a[MAXN];12 13 int cmp(const void *a, const void *b)14 {15 if ((*(data*)a).X == (*(data*)b).X)16 return (*(data*)a)... 阅读全文

posted @ 2012-04-01 16:30 getgoing 阅读(291) 评论(0) 推荐(0) 编辑

2012年3月31日

UVa 674 - coin change

摘要: 之前做过一道HDOJ上很类似的一道题,当时用的是枚举(依次从大到小枚举某一面值使用的次数,然后把所有情况相加),今天在UVa动态规划里看到这道题,一下子就没思路了,后来翻到了Rookie_Yang的代码,实在不理解。。硬着头皮求助队友,最后找到了正确的状态转移方程,才理解他的代码是优化过的;dp(i, j)表示 i 分钱用前 j(0,1,2,3,4) 种类型的硬币兑换总的方法;2012.4.2 以下注释中的考虑没必要,因为dp()中已经对j == 0的情况处理了。/* 记忆画搜索时还需要注意:对于 s[0..4][0],要在搜索前初始化(因为最终追溯到的是 s[0..4][0] 这 5 个数) 阅读全文

posted @ 2012-03-31 20:39 getgoing 阅读(620) 评论(2) 推荐(0) 编辑

UVa10405 - Longest Common Subsequence

摘要: 最大公共子序列,需要注意的是x[]最开始保存的是相应字符串的长度,在比较时应比较s1[x[1]-1]与s2[x[2]-1];水题,做一道过一道。。。 1 /* 10405 - Longest Common Subsequence */ 2 # include <stdio.h> 3 # include <string.h> 4 5 # define MAXN 1001 6 7 int lena; 8 int x[2]; 9 char s1[MAXN];10 char s2[MAXN];11 int ans[MAXN*MAXN];12 13 int get(int *x) 阅读全文

posted @ 2012-03-31 14:50 getgoing 阅读(284) 评论(0) 推荐(0) 编辑

UVa 103 - Stacking Boxes

摘要: DAG上的动态规划,需要注意最后要打印起点到终点的一条路,因此状态d[i]定义为从 i 出发的最长路的距离。UVa今天这是怎么了,两道题都是将近5min才出结果。 1 # include <stdio.h> 2 # include <string.h> 3 # include <stdlib.h> 4 5 # define MAXD 11 6 # define MAXN 31 7 8 int k, n; 9 int d[MAXN];10 int box[MAXN][MAXD];11 int g[MAXN][MAXN];12 13 int cmp(const 阅读全文

posted @ 2012-03-31 14:13 getgoing 阅读(230) 评论(0) 推荐(0) 编辑

UVa 111 - History Grading

摘要: 最大公共子序列;要读懂题目中对于输入的描述;仍然是上次的GDKOI最大公共子串的写法。 1 # include <stdio.h> 2 3 int n; 4 int x[2]; 5 int cor[21]; 6 int cur[21]; 7 int ans[441]; 8 9 int get(int *x);10 11 int main()12 {13 int i, t;14 15 scanf("%d", &n);16 for (i = 1; i <= n; ++i) 17 {18 scanf("%d", &t);19 阅读全文

posted @ 2012-03-31 13:02 getgoing 阅读(471) 评论(0) 推荐(0) 编辑

2012年3月30日

TLE: poj 1011 Sticks

摘要: Ozy的方法(dfs): 1 # include <stdio.h> 2 # include <string.h> 3 4 int f[51]; 5 int ok; 6 int length; 7 8 void dfs(int cnt, int len, int cur) 9 {10 int j;11 12 if (cnt == 0) {ok = 1; return;}13 14 --f[cur];15 16 len -= cur;17 if (len != 0)18 {19 j = len<cur ?... 阅读全文

posted @ 2012-03-30 12:56 getgoing 阅读(171) 评论(0) 推荐(0) 编辑

2012年3月29日

poj 3278 catch that cow

摘要: bfs,RE多次之后学习大牛的代码,不要惊讶怎么限定在100000范围内!更好的解法:http://www.cnblogs.com/longzhiri/articles/1555344.html 1 # include <stdio.h> 2 # include <string.h> 3 # include <queue> 4 5 using namespace std; 6 7 int n, k, x; 8 int d[100002]; 9 queue<int>Q;10 11 int main()12 { 13 while (~scanf(&q 阅读全文

posted @ 2012-03-29 20:33 getgoing 阅读(172) 评论(0) 推荐(0) 编辑

2012年3月28日

GDKOI2003 最大公共子串

摘要: AOJ链接:最大公共子串这道题求多个字符串的最大公共序列(非连续)的长度,题目中说明了所有串的乘积不超过30000;题解将状态记录在一个长度为30000的数组中,使用类似编码的方式(我的理解)进行存取;和算法导论上对LCS的解法不大一样(递归而不是递推,计算量会少一些),仍然是动态规划的思想;0MS,学习了。下面的代码是看懂了书上的后,自己写的;起先觉得第47、48行的恢复多余,后来发现并不是:包含回溯的过程,需要恢复原来的下标。 1 # include <stdio.h> 2 # include <string.h> 3 4 char str[102][102]; 5 阅读全文

posted @ 2012-03-28 22:47 getgoing 阅读(407) 评论(0) 推荐(0) 编辑

poj 1008 Maya Calendar

摘要: POJ的陷阱多多。。first WA:没考虑到一年中最后一天的情况,改了,也通过了一组discuss中的数据;2~3th WA:完全忽略了题目要求第一行输出test的个数;4th WA:输出格式中日的后面没有'.'。。。彻底服了 1 # include <stdio.h> 2 3 const char habbm[20][10] = {" ", "pop", "no", "zip", "zotz", "tzec", "xul", 阅读全文

posted @ 2012-03-28 13:46 getgoing 阅读(257) 评论(0) 推荐(0) 编辑

poj 1006 Biorhythms

摘要: 直接枚举(16MS,可以接受),测试数据有点纠结。 1 # include <stdio.h> 2 3 int p, e, i, d; 4 const int add[] = {1, 23, 28, 23*28, 33, 23*33, 28*33}; 5 6 int mod(int x, int m); 7 8 int main() 9 {10 int cnt, day, sta;11 12 cnt = 0;13 while (1)14 {15 scanf("%d%d%d%d", &p, &e, &i, &d);16 ... 阅读全文

posted @ 2012-03-28 11:23 getgoing 阅读(308) 评论(0) 推荐(0) 编辑

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 17 下一页

导航