上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页
摘要: 话说这题从我开始学线段树就开始做,直到今天才A掉,前后有近3个月吧。今天重新翻这个题,思路有点乱,看了一下大牛的代码。然后就自己写,没想到,居然敲了一遍就过了,激动啊~~3667Accepted3200K625MSC++2422B2011-10-25 17:50:22思路: 结构体定义包含:l, r, cov, ls, sum, rs。其中:ls表示从左边数连续的空余空间大小,rs表示从右边数连续的空余空间大小。sum表示整段上最大的空余空间大小。查询时。当查询到当段段的sum > len时,满足条件。更新时,当cov改变,同时要改变当前段的ls、rs、sum。当一段更新完后还要上传co 阅读全文
posted @ 2011-10-25 18:47 AC_Von 阅读(243) 评论(0) 推荐(0) 编辑
摘要: A: Zombie's Treasure ChestTime Limit (sec) 1.00 Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A b 阅读全文
posted @ 2011-10-24 20:11 AC_Von 阅读(332) 评论(0) 推荐(0) 编辑
摘要: data segmentstr1 db 100len1 db ? db 100 dup(?)str2 db 100len2 db ? db 100 dup(?)inf1 db 0ah, 0dh, 'Input string1:','$'inf2 db 0ah, 0dh, 'Input string2:','$'inf3 db 0ah, 0dh, 'string1 = string2 ? 'judg db 20h, 20h, 20h, '$'data endsstack segment stack d 阅读全文
posted @ 2011-10-22 20:58 AC_Von 阅读(3874) 评论(0) 推荐(0) 编辑
摘要: /*从昨天下午看这道题,一直到现在,以前做过一个类似连连看的题,跟这题差不多,就按那个思路写了,一步一步的搜,我晕,把bfs写暴也没能AC。上午请教牛人,说bfs时不要搜步数,直接搜直线数。就是一条路走到头,不撞南墙不死心(大体是这个意思^_^)。然后就是正常的bfs写法。入队列,出队列。。。 ps:注意标点符号T_T.*///My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 80;struct node{ int x 阅读全文
posted @ 2011-10-22 15:36 AC_Von 阅读(568) 评论(0) 推荐(0) 编辑
摘要: /*这题应该属于水题吧,基本不用什么大的处理,看懂题意就行。直接n次dfs,找出最大的length*///My Code: 16MS#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 30;int map[N][N];bool vis[N][N];int n;int ans;void dfs(int now, int t){ int f, i; for(f = 1, i = 0; i < n; i++){ if(vis[now][ 阅读全文
posted @ 2011-10-21 14:57 AC_Von 阅读(231) 评论(0) 推荐(0) 编辑
摘要: /*不明白为什么Ural把这题归到game里边,难到是因为这题是个游戏。。。很水的一道题,纠结了两天,以前没有接触过位压缩,估计学过位压缩的童鞋能够把这题直接秒掉,Orz各位做题神速的童鞋。。。 wwww wwww wwwb wwbb可以用二进制表示为:1100|1000|0000|0000;也就是说4*4方格里所有状态都可以用16位二进制表示,转成十进制后为0或者65535就完成了游戏。*///My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std; 阅读全文
posted @ 2011-10-21 10:37 AC_Von 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 这是一篇老文章,不过由于无法找到最初的发文地址,这里就不能粘贴原文网址了。本站转载此文与ACMer们共勉。感谢acmerfight供稿。题解:还记得2年前的一个晚上,我和一个女孩一起写完了这篇文章。写完后,她哭了,我笑了。然后,她走了,我哭了。2年后,我又找到她,这次,我没有让她走掉,她成了我的新娘。不知道什么时候,开始知道ACM;也不知道什么时候,开始喜欢上ACM。但是,我知道,我喜欢上了,而且不会后悔。我是大一的时候进的学校ACM队,那个时候,一切都是冰冷的,华东理工大学,在别人的眼里,只是每次给别人垫底的学校,次次如此。但是,我们不甘心,我们从不甘心,当我们主力队员中的一个,一个月拼命集 阅读全文
posted @ 2011-10-20 12:39 AC_Von 阅读(704) 评论(0) 推荐(1) 编辑
摘要: /*简单DFS,开始这题想复杂了,不知道用dfs还是bfs甚至都想写dijkstra,后来一狠心写了个dfs,1Y了,^_^ ,可能题目的数据比较若吧,呵呵,感觉主要还是把图抽出来这地方,有点像模拟题了。输出是加了一个pre[]存放当前结点的前驱,然后把pre[]包含的结点信息入栈,然后出栈好了。*///My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 300;char str[110][N];int map[110] 阅读全文
posted @ 2011-10-20 11:32 AC_Von 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 写了整整一天,到晚上才出过样例,然后各种wa, tle ,ole !!!code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 11;char map[N][N];int hr[N][N];int hc[N][N];int hx[3][3][N];int z;void dfs(int i, int j){ int x, y, k, l; if( i < 0 && z){ for(k = 0; k < 9 阅读全文
posted @ 2011-10-19 20:23 AC_Von 阅读(189) 评论(0) 推荐(0) 编辑
摘要: /*感觉我的做法很麻烦,一个只存+-符号的数组, 一个存所有操作符的队列,再来一个队列存操作数(比如1,2, 1011(10.11的情况))。然后就是暴搜。。。*//*My Code: 297MS*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 50;char opr2[N];char opr[N];int opn[N];int cnt, n;void dfs(int p, int p2, int m, int sum, int 阅读全文
posted @ 2011-10-18 21:20 AC_Von 阅读(370) 评论(0) 推荐(0) 编辑
摘要: 纠结的高精度,终于拿下了。。。转移方程很简单 dp[i][j] = dp[i-1][j-k] {k| 0, 1, 2 .... , 9},高精度整了一下午。悲剧,各种wa。。。重新敲了一遍,终于过了。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 550;const int M = 50;const int inf = 10000;int dp[M+5][N][M+5];void add(int a[M+1], int b[M+1] 阅读全文
posted @ 2011-10-18 17:15 AC_Von 阅读(264) 评论(0) 推荐(0) 编辑
摘要: /*用到了class, template,析构函数,构造函数,C++菜鸟一只,大牛无视。各种bug,待修改。。。*///My Code:#include <iostream>#include <cstdio>#include <cmath>#include <cstring>using namespace std;const int N = 256;char map[N][N];template <class T>class Node{public: T data; Node * next; Node(const T &e, 阅读全文
posted @ 2011-10-17 22:05 AC_Von 阅读(784) 评论(0) 推荐(0) 编辑
摘要: 用dfs搜索每种情况所对应的sg值(这里也就是对应的是N位还是P位),若下一步为P位,则当前一步为N位。。。代码:#include <iostream>#include <cstdio>using namespace std;const int N = 55;char map[N][N];int m, n;int judge(int i, int j){ if(map[i][j] == '0' && map[i][j+1] == '0' && map[i+1][j] == '0' & 阅读全文
posted @ 2011-10-12 13:17 AC_Von 阅读(346) 评论(0) 推荐(0) 编辑
摘要: /*今天一翻以前做的sg函数的题,这题原来的代码居然跑781MS, 我晕!又重新写了一遍,开始vis数组定义成全局变量了,WA。。。T_TMy Code(78+MS):*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1005;struct node{ int num; int edg[N];}e[N];int sg[N];int mex(int t){ if(sg[t] != -1) return sg[t]; int i; . 阅读全文
posted @ 2011-10-11 17:32 AC_Von 阅读(205) 评论(0) 推荐(0) 编辑
摘要: /*第一道树形dp的题,感觉树形dp就是在dp的基础上加了树这个环境,建树——DFS。思想上还是基本的动态规划思想(最优子结构,重叠子问题)。参考解题报告终于把这题做出来的。思路:dp[t][j]为以t为根的子树,保留j条边时的最优情况,map[i][j]为i结点到j结点构成的边的权值。当t与一个孩子相连时:dp[t][j] = max(dp[L][j-1]+map[L][t], dp[R][j-1] + map[r][t]);当t结点与两个孩子相连时:for(j = 0; j <= i-2; j++){ //因为j表示的是除去t -> L 和 t -> R两边之后两个子树的 阅读全文
posted @ 2011-10-10 13:13 AC_Von 阅读(306) 评论(0) 推荐(0) 编辑
摘要: /*题意:对1到N这些数进行排列,1在最左边,相邻的两个数之差不能超过2,求有多少种排列方法? 思路:已知1在最左边,跟1相邻的只能是2、3。当2跟1相邻时后边的部分就是dp[n-1] 。当3在1后边,2在3后边时,前三位确定,剩下的就是dp[n-3]。最后剩下一种情况,再加1。 dp[i] = dp[i-1] + dp[i-3] + 1;*/#include <iostream>#include <fstream>using namespace std;const int N = 60;long long dp[N];int main(){ //fstream cin 阅读全文
posted @ 2011-10-09 13:15 AC_Von 阅读(272) 评论(0) 推荐(0) 编辑
摘要: /*题意:求【1 to 10^9】范围内各位数字之和为s的数的个数; 思路:定义dp[i][j] (i = 1 to 9, j = 1 to 81),表示位数为i的数各位数之和为j的数的个数。dp[i][j] = (i - 1位数最低位全部补0) + (i - 1位数最高位补j - k {k| 1 <= k <= 9} )。所以转移方程就是 dp[i][j] = dp[i-1][j] + sum(dp[i-1][j - 1] , dp[i-1][j-2] , ... , dp[i-1][j-9]);ps:注意s = 1 的时候是10而不是9,因为10^9也算在s = 1里边My C 阅读全文
posted @ 2011-10-09 10:00 AC_Von 阅读(479) 评论(0) 推荐(0) 编辑
摘要: /*参考《算法导论》My Code:*/#include <iostream>#include <cstdio>#include <string>using namespace std;const int N = 1000;string T, P;int pi[N];void COMPUTER_PREFIX_FUNCTION(string P){ int m = P.length(), i, k; for(k = pi[0] = -1, i = 1; i < m; i++){ while(k > -1 && P[k+1] != P 阅读全文
posted @ 2011-10-08 17:55 AC_Von 阅读(770) 评论(0) 推荐(0) 编辑
摘要: 思路:dp,转移方程 dp[i] = min(dp[i-1] + 1, dp[i - j*j] + 1);这个转移方程很好理解,类似0-1背包,买j*j的这块地还是不买。跟POJ_3267 The Cow Lexicon很像。ps:上午wa了好几次,下午昨晚福州的网赛又拿过来这个题,不知道改了哪地方,没积分钟就ac了。看来是老天可怜我网赛被虐。。。T_TMy Code:#include <iostream>#include <cstdio>#include <cstring>#include <math.h>using namespace std 阅读全文
posted @ 2011-10-07 19:22 AC_Von 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 表示cin很不靠谱,10^5的数据量都能TLE 改成scanf 300+ms。My Code:#include <iostream>#include <algorithm>#include <cstdio>#include <fstream>using namespace std;const int N = 100005;class phage{public: int di; int ti;}p[N];bool cmp(phage a, phage b){ if(a.ti != b.ti) return a.ti > b.ti; else 阅读全文
posted @ 2011-10-07 19:05 AC_Von 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 昨晚想着做了的,到宿舍乱的又没心情了。发现高精度真的不熟,各种错误,Crash, MLE, WA。。。最后看到有人一个数组空间存两位数,精度为100时才不MLE。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1000;int ans[N*2][N+1];int tmp[N+1];void add(int a[], int b[], int res[]){ int i; for(i = N; i >= 0; i--){ res 阅读全文
posted @ 2011-10-07 09:27 AC_Von 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 跟Vresion 1一样,就是加了高精度。表示高精度还是不熟。。。My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1000;void add(int a[], int b[], int res[]){ int i; for(i = N; i >= 0; i--){ res[i] = a[i] + b[i]; } for(i = N; i >= 0; i--){ if(res[i] > 9){ ... 阅读全文
posted @ 2011-10-06 22:02 AC_Von 阅读(305) 评论(0) 推荐(0) 编辑
摘要: /*拿到这题已经好几天了,因为国庆放假回家,家里正好断网,一直没做,今天回到学校终于把它做了。表示已经被dp虐了n久了,还是不得要领,只能守着dp的解题报告过日子。T_T...题意:给一个串mes[], 一个字典dic[],求让这个串完全匹配字典里的串时删除的最小元素个数。思路参考自:http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122638.html:按mes[]串从后往前匹配,最坏的情况是 dp[i] = dp[i+1] + 1;设 pm是mes[]的下标,如果出现从mes[i] 到 mes[pm] 这一段正好和dic[.. 阅读全文
posted @ 2011-10-06 20:40 AC_Von 阅读(1043) 评论(0) 推荐(0) 编辑
摘要: 这题纠结了一天,到现在也没搞很明白,转移方程 dp[i][j] += dp[i-j][k]; ( 0 <= k < j),表示将最后一层(最高的一层)拿掉之后的所有子结构的和。代码:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 501;long long dp[N][N];int main(){ //freopen("data.in", "r", stdin); int n, i 阅读全文
posted @ 2011-10-01 19:20 AC_Von 阅读(268) 评论(0) 推荐(0) 编辑
摘要: /*这题推规律,f[i] = f[i-1] + f[i-2]; f[1] = f[2] = 2;原因:当只加一个r或者w时,得到的总类数就是f[i-1];当添加rb 或者wb 时。得到的种类数就是f[i-2];My Code:*/#include <iostream>#include <cstdio>using namespace std;int main(){ //freopen("data.in", "r", stdin); long long f1, f2, f3; int n, i; while(~scanf(" 阅读全文
posted @ 2011-09-30 21:50 AC_Von 阅读(336) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页