BZOJ1933 [Shoi2007]Bookcase 书柜的尺寸

老早之前就听说过的题。好像讲过不只一遍。不过才从bzoj上翻出来。 记得是神奇的dp优化。为啥这年头卡常数的题这么多。 首先肯定这玩意多项式可解。六维状态肯定能搞定。然后会mle+tle。 首先考虑从高到低放书,那么后面的如果不新开一行的话对高度没有影响。瞬间少了3维状态。 然后发现只要知道两维的总宽度和当前是第几位,就能知道第三维的宽度。于是一维2100缩70,开滚动可过。 当然还是需要一些常数优化的技艺。比如用宽度直接判断这一行有没有书。这样可以省下不少时间,而且好像只能这样才存得下。64MB太紧了点。另外把函数里的int改成const int&会变慢,不知为何。 居然花了这么久才搞出来。我太年轻了。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct book { int w, h; }; inline bool cmpBook(const book& a, const book& b) { return a. h > b. h; } const int maxn = 71; const int maxw = 2109; const int inf = 0x3f3f3f3f; int n, f[2][maxw][maxw], sw; book a[maxn]; inline void upmin(int& _a_, int _b_) { if (_a_ > _b_) _a_ = _b_;...

December 22, 2014 · 2 min · laekov

20141222

不久之后要会考了,再过不久要期末了。教育部在放风,大概以后如果noi拿不到金牌的话就得和别人一样地高考了。 一直在oi里面坚持也没有怎么想过高考的事,一直只是当作一个额外的好处。如果让我不上大学给我一次ioi的机会,我想我也不会犹豫的。 本来,上什么大学,也不是什么重要的事情。作为oier,我知道,只向上看,是个很好的品质,但是不是什么好的策略。如果你非要落魄到拿着期末成绩去让大学收你,那你该考虑换个差点的大学了。 因为做过鸡头,所以对做凤尾产生了抵触吧。 当然,显然,学校,老师都不这么想。虽然我来这里的目的也完全不是因为高考,但是既然穿上这身校服,你也没有办法。 背起包走回教室的感觉真的很像退役了。 大本的崭新的练习册让人很压抑。如何在两周内补完一个学期的内容是一个很艰巨的问题。也许多看书多刷题是个不错的选择。 既然有人要来挑战,那就让他们看看。

December 22, 2014 · 1 min · laekov

BZOJ3809 Gty的二逼妹子序列

好一道卡常数。不仅卡时间,还卡空间。堪称丧心病狂的极致。 首先因为空间小所以得用莫队。然后不知为何树状数组没有直接分块跑得快。 没有救啦。 #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <algorithm>   usingnamespacestd;   structqry {     intl, r, a, b, n; };   int_d_; #define readInt(_x_) { \     int& _s_ = _x_; \     while(!isdigit(_d_ = getchar())); \     _s_ = 0; \     while((_s_ = _s_ * 10 + _d_ - 48), isdigit(_d_ = getchar())); \ }   constintmaxn = 100009; constintmaxm = 1000009;   intn, m, bsz, a[maxn], c[maxn], w[maxn], b[maxn], ans[maxm];...

December 22, 2014 · 2 min · laekov

BZOJ1875 [SDOI2009]HH去散步

乍一看矩阵水题,然后发现不能走回头路。 于是改一下把边当做点,把点当作转移,转移的时候就可以避免走过去就走回来的情况了。 说好的复习会考呢? #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define _l (long long int) const int mod = 45989; const int maxn = 123; class matrix { public: int n, a[maxn][maxn]; inline matrix() { } inline matrix(int n0, bool one = 0) { n = n0; memset(a, 0, sizeof(a)); if (one) for (int i = 0; i < n; ++ i) a[i][i] = 1; } void operator =(const matrix& x) { n = x....

December 21, 2014 · 2 min · laekov

BZOJ3728 PA2014Final Zarowki

贪心。从小到大每个灯泡找个小于等于它的最接近的房间去照。 剩下的照不亮的房间直接换。 剩下的背包空间把已经匹配的差最大的换掉。 第一步要拿堆维护一下。剩下的直接排序。 然后把nie写成-1了,no save。 #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; typedef long long di; #ifdef WIN32 #define difmt "%I64d" #else #define difmt "%lld" #endif const int maxn = 500009; int _d_; #define readInt(_x_) { \ int& _s_ = _x_; \ while (!isdigit(_d_ = getchar())); \ _s_ = 0; \ while ((_s_ = _s_ * 10 + _d_ - 48), isdigit(_d_ = getchar())); \ } int n, k, p[maxn], w[maxn], x[maxn], t;...

December 21, 2014 · 1 min · laekov

BZOJ2565 最长双回文串

以前觉得不会,仔细想想觉得还是挺水。 manacher找出所有中心回文串,然后用单调队列扫一下每个位置往左最长和往右最长就行。找位置比较烦不过还是比较好写的。 重点是写出了在windows下拿for循环对拍,虽然异常丑。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 200009; int n, l[maxn], q[maxn], vx[maxn], vy[maxn]; char a[maxn]; void manacher() { l[0] = 1; for (int i = 1, j = 0; i < (n << 1) - 1; ++ i) { int r = ((j + 1) >> 1) + l[j] - 1; int p = i >> 1, q = i - p; l[i] = (r >= q) ? min(r - q + 1, l[(j << 1) - i]) : 0;...

December 20, 2014 · 2 min · laekov

80MSWC diary 4.1

昨天就考完了不过今天还是讲了一天的课。 上午是罗翔宇的杂题。感觉好多题他上次都讲过不过就是记不得怎么做了。看来听课效率有待提高。 下午是讲icpc的题加各种神奇的玩意。感觉比较好玩,不过有点偏题啊。然后做表去了也没大听。 毕竟我还是太年轻对吧,七天就水过去了。还被学军的大爷们虐成狗了。

December 18, 2014 · 1 min · laekov

BZOJ2105 增强型LCP

最初以为是splay维护Hash的简单题。顺手开心地敲了个splay还是指针版的。 然后发现tle了。 然后知道了可以暴力重新建串。 然后拿splay暴力重新建串。 然后又tle了。 然后不得已改成了随机线性存取表,过之。 我还是太naive了啊。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef unsigned long long qw; #define _l (long long int) const int maxn = 200009; const int base = 233; struct str { char a[maxn]; int len; inline str() { len = 0; } inline void read() { scanf("%s", a + 1); len = strlen(a + 1); } inline char operator [](const int& x) const {...

December 17, 2014 · 2 min · laekov

80MSWC diary 3.5

昨天是day3明天是day4所以今天是day3.5。 讲了一天课。 上午+晚上是图论。感觉图论的东西比较神。好像基本都是cf原题吧。好多东西要和其它的诸如数据结构和dp之类的东西结合,还有数学也比较重要。 下午是fft相关。先讲了一下fft的原理,虽然我觉得讲得除了好玩以外没什么特点,也没有用最好理解的方式来讲。然后期待的例题好像也不杂。然后怎么就扯到牛顿迭代上去了。不过这玩意以前没用过感觉还挺神奇的,改天找道题试试。 晚上无聊的时候写了个后缀数组,这种东西还是要不时写写不然都要忘了。然后后缀自动机的构建依然不太能理解。看来我还是太弱了WUW 然后明天是最后一天了。我虽然年轻,但是还是要努力一点的。

December 16, 2014 · 1 min · laekov

BZOJ1692 [Usaco2007 Dec]队列变换

最初以为是水题,直接写个dq交上去不对。 看了下题解才知道是后缀数组。好久不写都快不会写了。 把原串倒过来扔一起排一下就行了。 #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; const int maxn = 60009; int n; int sa[maxn], rk[maxn], ro[maxn], w[maxn], o[maxn]; char a[maxn]; void sufixArray(int n) { memset(w, 0, sizeof(w)); for (int i = 0; i < n; ++ i) ++ w[(int)a[i]]; for (int i = 1; i < 123; ++ i) w[i] += w[i - 1]; for (int i = 0; i < n; ++ i) sa[-- w[(int)a[i]]] = i;...

December 16, 2014 · 2 min · laekov