随笔分类 -  基础算法

摘要:循环 题解:http://trinklee.blog.163.com/blog/static/238158060201482371229105/ 刚开始把问题想的复杂了,想到了bzoj覆盖问题,但是俩者之间没有什么关系。那个是二分取得最大值。 本道题里,覆盖方式只可能出现题解里的6种。所以统计好前缀和就可以了。 各种变量要看清。 #include #include #include... 阅读全文
posted @ 2016-07-13 15:24 invoid 阅读(388) 评论(0) 推荐(0)
摘要:A*搜索。 A*搜索的基础百度百科(实在偷懒没看论文之类的),在这里不说了。 A*搜索很关键的是h(n)估价函数的选取(表示现在到结束节点需要的距离) 设d(n)为实际到结束节点的距离。h(n) #include #include using namespace std; const int dx[]={2,1,-1,-2,-2,-1,1,2},dy[]={1,2,2,1,-1,-2,-2... 阅读全文
posted @ 2016-06-26 11:46 invoid 阅读(199) 评论(0) 推荐(0)
摘要:前缀和。 维护一下前缀和,枚举。 按道理复杂度在当时是过不去的吧。。 #include #include #include using namespace std; const int maxn = 5000 + 10; const int k = 5001; int s[maxn][maxn]; int n,r,res; int main() { memset(s,... 阅读全文
posted @ 2016-06-15 22:05 invoid 阅读(166) 评论(0) 推荐(0)
摘要:每个数i作为约数的次数为n/i。累加即可,复杂度O(n)。 阅读全文
posted @ 2016-03-26 09:50 invoid 阅读(122) 评论(0) 推荐(0)