上一页 1 2 3 4 5 6 7 8 9 10 ··· 18 下一页
摘要: 堆+huffman树。 huffman二叉树构造法就是每次把最小的俩个合并起来,构成一个树。 但k叉树每回减少(k-1)个,可能最后会有一个坑位被浪费掉,导致答案增加(用心去感受) 于是我果断回忆去年他们游记里面写到,多余的先合并下。。 然后1A了。。。 #include #include #include #include #include using namespace ... 阅读全文
posted @ 2016-06-28 08:54 invoid 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 最短路+最小割 首先如何使最短路变长?就是要每一条最短路都割一条边。 我们求出每个点到点1和点n的距离,就可以知道哪些边在最短路上(一开始没有想到求到0和n的距离,想用floyd,但是n=500,怕超时。) 第二步呢,我们把每条在最短路上的边加入一个新图,跑最小割就可以了(把所有最短路都割掉一条边,最短路就变长了,这个也没想到) #include #include #include... 阅读全文
posted @ 2016-06-27 19:55 invoid 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 拓扑排序+堆。 转自popoqqq神犇。 反向建图跑拓扑排序然后逆序输出。 为什么不能正的来呢,因为不知道选当前菜要先制作哪种菜。 逆序过来跑拓扑的话,也能保证满足限制条件编号小的在前面。 题外话:我都打完了才发现第三个样例输出不对,一看题直接就弃疗了。。事实证明就改动几个字母。。。。 toposort我一直喜欢叫”土拨”sort,可能是因为我口语不好吧。。。 #includ... 阅读全文
posted @ 2016-06-27 17:08 invoid 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 暴力。 O(n^6)暴力卡过,72ms。 莫名其妙做这道题时感觉十分烦躁,难受,只能这样了。 O(n^4)的方法是这样差分一下。判断的时候tmp=t[i][j],t[i][j]-=tmp,t[i+r][j]+=tmp,t[i][j+c]+=tmp,t[i+r][j+c]-=tmp,同时查看是否合法。 还有一个更优化的是如果r,c不行,r*q和c*q也不行。这个好像就是正解的办法? 为什么... 阅读全文
posted @ 2016-06-27 12:48 invoid 阅读(171) 评论(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 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 数学。 x^2 % n = 1 则 (x+1)(x-1) = kn. 设 x+1 = k1*n1, x-1=k2*n2。 则 k1*k2=k , n1*n2=n。 算出每个大于sqrt(n)的约数,然后分别作n1,n2尝试是否可行。 算x一定要取模。否则1会变成n+1。 #include #include #include #include #include using names... 阅读全文
posted @ 2016-06-25 22:58 invoid 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 费用流。 传说中建模之集大成之题。。。 https://www.byvoid.com/blog/noi-2008-employee 题解 题解里面关于建模已经讲的很全了。 我根据自己的理解写写建模的实际意义。 如果a[i]-a[i-1]>=0,代表需要新雇佣人。否则就代表有人离开了。(离开并不一定要在t[i]+1天,如果后面人多余的话,很早就会离开)。 1.建模为S->i容量为 a[i... 阅读全文
posted @ 2016-06-25 13:50 invoid 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 水题。 按位处理,复杂度O(nlogm)。真心好看。。。。。 #include #include #include using namespace std; const int maxn = 100000 + 10; int n,m,k,l,f1,f2,res; char s[20]; int op[maxn],t[maxn]; inline int calc(int f,int i... 阅读全文
posted @ 2016-06-25 09:39 invoid 阅读(150) 评论(0) 推荐(0) 编辑
摘要: splay. 就是splay,没别的了。 #include #include #include using namespace std; const int maxn = 600000 + 10; const int inf = 0x3f3f3f3f; struct Splay { int v[maxn],s[maxn],sum[maxn]; int l[maxn],r... 阅读全文
posted @ 2016-06-25 09:07 invoid 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 状态压缩dp。 一道很好的dp题。 我们在选的时候并不知道它会对后面的选择造成什么影响,所以不能正向dp。 f[i][s]表示第i次选择后,选择的宝物二进制为s的期望得分。 初始状态均为0,答案为f[0][0]。 #include #include #include using namespace std; const int maxn = 20; const int maxm =... 阅读全文
posted @ 2016-06-25 08:59 invoid 阅读(133) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 18 下一页