2013年3月31日

ZOJ Monthly, March 2013 - A A Simple Tree Problem

摘要: http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=4959题意:给一棵树,树的每个节点初始值为0,要求支持两种操作:o k : 将k下的子树值取反q k : 查询k下的子树值有多少个为1思路:化树结构为线性,每个点管理一个区间。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using name 阅读全文

posted @ 2013-03-31 17:12 aigoruan 阅读(437) 评论(0) 推荐(1) 编辑

2013年3月23日

hdu 4514

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4514题意:先判断给定的图中是否有环,没有则对森林进行求最长路。思路:dfs判断是否有环,然后对每棵树,两次dfs求最长路,最后取最大的。View Code #include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#pragma comment(linker, "/STACK:36777216")//开大点栈using namespace std; 阅读全文

posted @ 2013-03-23 10:57 aigoruan 阅读(219) 评论(0) 推荐(0) 编辑

2013年3月22日

hdu 4513

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4513和这个题很像,YY一下就可以了http://www.cnblogs.com/aigoruan/archive/2012/07/08/2581217.html思路:二分+暴力匹配View Code #include<set>#include<map>#include<stack>#include<queue>#include<cmath>#include<bitset>#include<string>#include< 阅读全文

posted @ 2013-03-22 23:48 aigoruan 阅读(435) 评论(0) 推荐(0) 编辑

2013年3月8日

用python写的一个简单二叉树排序类

摘要: #coding:utf-8max_val = [99999999,-99999999]class Mysort(object): "Mysort to sort a int array" def __init__(self,List): self.mylist = List self.bs = '' self.Dict ={0:min,1:max} self.select = '' def buildTree(self,rt,L,R):#树一棵二叉树,每个节点维护当前子树的最小值(最大值) ... 阅读全文

posted @ 2013-03-08 22:46 aigoruan 阅读(618) 评论(1) 推荐(0) 编辑

2012年10月30日

ACM第五乐章--数论

摘要: /*Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).*/#include<stdio.h>#include<string.h>long long mod = 9901;long long exp(long long a,long long b,long long c){ long long ans = 1; while( 阅读全文

posted @ 2012-10-30 09:18 aigoruan 阅读(176) 评论(0) 推荐(0) 编辑

ACM的第三乐章---状态DP

摘要: poj 1185http://poj.org/problem?id=1185/*Problem: 1185 User: ruan123Memory: 2128K Time: 266MSLanguage: G++ Result: Accepted说下dp方程:dp[i][j][k] 为第i行状态为Sj,第i-1行状态为Sk时前i行最多能放置的炮数。 */#include <stdio.h>#include <string.h>#include <stdlib.h>int dp[105][65][65];int s[105],map[105],cnt,c[... 阅读全文

posted @ 2012-10-30 09:16 aigoruan 阅读(194) 评论(0) 推荐(0) 编辑

ACM的第二乐章--BFS

摘要: bfs和dfs一样,也是以树形搜索形状进行的,只不过dfs是以树根开始一个个的搜索,而bfs则以步数、层次展开搜索,也就是从树根一层层的向外拓展。这种拓展需要的空间一般都是指数级的,所以不能像dfs一样灵活搜索,往往都是在一定的剪枝策略下展开的,因而bfs一般适合求解最优解。标志性的bfs里会有一个... 阅读全文

posted @ 2012-10-30 09:11 aigoruan 阅读(164) 评论(0) 推荐(0) 编辑

2012年10月28日

c++访问声明有关猜测

摘要: c++访问声明:访问声明的方法就是直接把基类中的保护成员或公有成员 写在私有派生类定义式中的同名段同,同时给成员名前冠以基类名和作用域标识符"::"。如下面的例子:View Code #include<stdio.h>#include<string.h>#include<iostream>using namespace std;class A{ public: A(int x1){x = x1;} void show(){cout<<"x="<<x<<endl;} // void s 阅读全文

posted @ 2012-10-28 19:08 aigoruan 阅读(212) 评论(0) 推荐(0) 编辑

2012年10月26日

2012 天津赛区 A题 hdu 4431

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4431题意:给13个牌,问你可以糊那些牌。思路:现场队友提醒就知道思路了,枚举每一张牌,看能不能win。却被麻将的规则虐了,题目好像没说下面的数据呀:1s 1s 1m 9m 1p 9p 1c 2c 3c 4c 5c 6c 7c (糊9s)View Code #include<stdio.h>#include<string.h>#include<iostream>#include<set>#include<utility>using namespace 阅读全文

posted @ 2012-10-26 18:17 aigoruan 阅读(943) 评论(0) 推荐(0) 编辑

2012年10月24日

2012年 湖南第八届省赛总结

摘要: 执身赛就不说了正式赛开始前,就说好,7个中文题,每人负责2个,看到水题就让W上,剩下的英文题就由R和G慢慢看。比赛开始了,大家就开始看题了,R首先看A题,是个数学题,应该是水题,但题目不是很明白,想推一下。不久G看懂B题了,让W写了,这时R放弃看A题,把A题弄给W,让W看,改看其它的题觉得E题是个字符串处理,D题是个大数,J题可能是个DP,都放下了;不久B题出了。然后不久A题也写好了,因为题目上写有trick,R担心W没弄好,提醒了他,还好,都过了。这个时候中文题看完了,但是不能刷榜,无奈只能随便看英文题了,R拿到了C题,看了下数据强度,感觉纯STL库也可以做,就开始构思了。A题出了后,没有用 阅读全文

posted @ 2012-10-24 20:08 aigoruan 阅读(175) 评论(0) 推荐(0) 编辑

导航