BZOJ2716 [Violet 3]天使玩偶

看时间比较宽么,写一个log^2的cdq+树状数组么。 然后被2648卡了。学kd-tree吧。 naive。 #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; int _d_; #define readInt(_s_) {\ _s_ = 0;\ while (!isdigit(_d_ = getchar()));\ while ((_s_ = _s_ * 10 + _d_ - 48), isdigit(_d_ = getchar()));\ } struct point { int x, y, t, i; }; const int maxn = 500009; const int maxz = 1000009; const int inf = 0x3f3f3f3f; inline bool cmpPoint(const point& a, const point& b) { return a....

November 24, 2014 · 3 min · laekov

BZOJ1492 [NOI2007]货币兑换Cash

cdq分治第二题。 最初没看清题所以一直不会做。晕。 cdq教程里的模板题。 显然所有卖都是卖完,买都是把钱买光。 f[i]表示第i天结束后最多持有b卷的数量,ans表示当前最多能赚到的rmb。 方程是: f[i] = max(ans, f[j] * r[j] * a[i] + f[j] * b[i]) / (a[i] * r[i] + b[i])。 移项得: f[j] = -(a[i]/b[i]) * (r[j] * f[j]) + (r[i] * a[i] + b[i]) / b[i] * f[j]。 把r[j]*f[j]看作x,把f[j]看作y,好像可以斜率优化了。  不急,f[j]好像没有单调性吧?不对,好像a[i]/b[i]也没有单调性!? 平衡树维护凸壳?想起了上回那道hnoi的作业,调了一晚上,怎么能这样。 然后,其实可以cdq。 每次对右边有影响的是左边的凸壳,所以先跑左边,计算左边对右边的影响,再跑右边。这回是中序遍历,而不是Mokia那题的后序。 原来cdq可以这么神奇。 然后又把凸壳写丑了TT。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 100009; double ans, s, f[maxn], a[maxn], b[maxn], r[maxn]; int n, h[maxn], tmp[maxn], t; inline double getx(const int& i) { return f[i] * r[i]; } inline double gety(const int& i) { return f[i];...

November 23, 2014 · 2 min · laekov

BZOJ3428 [Usaco2014 Jan]Cow Curling

补昨天的题。 比较好想的计算几何。就看每个点在不在另一个颜色的点形成的上凸壳下面,下凸壳上面。这个用二分可以做到单次log。用单调应该也能O(n)。 但是写起来非常坑,要用long long,还有各种等号啥的。 写win32 app来显示点的代码比交上去的代码还长。开心。      #include <cstdio> #include <algorithm>   usingnamespacestd;   typedeflonglongqw;   #define _l (qw)   structpoint {     intx, y;     point (intx0 = 0, inty0 = 0) {         x = x0, y = y0;     }     inlinevoidread() {         scanf("%d%d", &x, &y);     } }; structvect {     intx, y;     vect(intx0 = 0, inty0 = 0) {         x = x0, y = y0;     }     vect(constpoint& a, constpoint& b) {...

October 22, 2014 · 3 min · laekov

BZOJ2338 数矩形

本来以为是上回那道数正方形的原题的。结果发现不要求边与座标轴平行,于是我就naive了。然后数据结构变身计算几何一堆东西吼吼。 矩形的对角线相等且互相平分(来自初二数学书)。把所有点对的中点找出来,把所有相等且平分的放一起用单调性,有点像旋转卡(qia3)壳(qiao4)的做法。jason_yu说暴力枚举都能过,而且他跑得比我快! 计算几何也写得比较naive。调了半天啊。 毕竟我弱嘛。 #include <cstdio> #include <cmath> #include <algorithm> using namespace std; typedef long long qw; #ifdef WIN32 #define lld "%I64d" #else #define lld "%lld" #endif #define _l (qw) const double eps = 1e-8; const int maxn = 1509; #define sqr(x) ((x)*(x)) #define dist(a,b) (sqr(a.x-b.x)+sqr(a.y-b.y)) #define nextele(_x_) ((_x_+1==r)?(l):(_x_+1)) struct point { qw x, y; point(qw x0 = 0, qw y0 = 0) { x = x0, y = y0; } inline point operator =(const point& a) {...

October 21, 2014 · 3 min · laekov