noip2015_message.cc

// Source code from laekov at noip 2015 day1 #define PRID “message” #include #include #include using namespace std; const int maxn = 200003; int ans, n, t[maxn], d[maxn], v[maxn]; int walk(int po) { if (d[po]) return n; int p(po); d[p] = 1; v[p] = po; while (p) if (!d[t[p]]) { d[t[p]] = d[p] + 1; v[t[p]] = po; p = t[p]; } else if (v[t[p]] == po) return d[p] - d[t[p]] + 1; else return n; return n; }...

November 17, 2015 · 1 min · laekov

noip2015_magic.cc

// Source code from laekov at noip 2015 day1 #define PRID “magic” #include #include #include using namespace std; const int maxn = 41; int n, a[maxn][maxn], px[maxn * maxn], py[maxn * maxn]; int main() { freopen(PRID “.in”, “r”, stdin); freopen(PRID “.out”, “w”, stdout); memset(a, -1, sizeof(a)); scanf("%d", &n); px[1] = 1; py[1] = (n + 1) >> 1; a[px[1]][py[1]] = 1; for (int i = 2; i <= n * n; ++ i) { if (px[i - 1] == 1 && py[i - 1] < n) px[i] = n, py[i] = py[i - 1] + 1; else if (py[i - 1] == n && px[i - 1] > 1) px[i] = px[i - 1] - 1, py[i] = 1; else if (px[i - 1] == 1 && py[i - 1] == n) px[i] = 2, py[i] = n; else if (a[px[i - 1] - 1][py[i - 1] + 1] == -1) px[i] = px[i - 1] - 1, py[i] = py[i - 1] + 1; else px[i] = px[i - 1] + 1, py[i] = py[i - 1]; a[px[i]][py[i]] = i; } for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) printf("%d%c", a[i][j], (j == n) ?...

November 17, 2015 · 1 min · laekov

recite.cc

#include <bits/stdc++.h> using namespace std; const int maxn = 203; const int maxstr = 1003; int n, ted[maxn], tec; char g[maxstr], sq[maxn][maxstr], sa[maxn][maxstr]; void setcol(int c) { printf("\33[%dm", c); } void init() { FILE* ipf(fopen(“bstk.txt”, “r”)); n = 0; while (fgets(g, sizeof(g), ipf), !feof(ipf)) { char* p; p = strstr(g, “—”); if (!p) continue; *p = 0; strcpy(sq[n], g); strcpy(sa[n], p + strlen("—")); ++ n; } fclose(ipf); printf("%d problems loaded\n", n); }...

July 8, 2015 · 1 min · laekov

bzoj2850.cc

#include #include #include using namespace std; typedef long long dint; #ifdef WIN32 define lld “%I64d” #else define lld “%lld” #endif #define _l (long long int) struct kdnode { int p[2], r[2][2], v; dint h; kdnode *ch[2]; inline void update(); }; struct candy { int a[2], v; void read() { scanf("%d%d%d", a, a + 1, &v); } }; typedef struct biobj { double x, y; biobj() {} biobj(double xo, double yo) { x = xo, y = yo; } } point, vect; inline biobj operator +(const biobj& a, const biobj& b) { return biobj(a....

July 1, 2015 · 3 min · laekov

bzoj4134.cc

#include #include #include using namespace std; struct edge { int t; edge *ne; }; struct node { int sz, rv; node *ch[2]; }; const int maxn = 100003; const int maxnd = maxn * 46; const int maxl = 19; int n, vo[maxn], f[maxn], sp[maxn], tsp; node nbuf_arr[maxnd], *nbuf(nbuf_arr), *rt[maxn]; edge ebuf_arr[maxn « 1], *ebuf(ebuf_arr), *head[maxn]; #define szof(p) (p?p->sz:0) inline void pushDown(node* q, int l) { if ((q-> rv » l) & 1) swap(q-> ch[0], q-> ch[1]); if (q-> ch[0]) q-> ch[0]-> rv ^= q-> rv; if (q-> ch[1]) q-> ch[1]-> rv ^= q-> rv; q-> rv = 0; }...

June 27, 2015 · 3 min · laekov

bzoj2781.cc

#include #include #include using namespace std; struct mov { int x, y, d; mov() { x = y = d = 0; } void rot(); }; const int maxl = 33; int le[maxl], t; mov a[maxl], b[maxl]; void mov :: rot() { int xo(x), yo(y); y = xo, x = -yo; d = (d + 1) & 3; } mov operator +(mov a, mov b) { mov r; for (int i = 0; i < a....

June 26, 2015 · 2 min · laekov

bzoj3329.cc

#include #include #include using namespace std; typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int) const int maxl = 103; int bi[maxl], le; dint f[maxl], g[maxl][2]; dint digDP(dint n) { le = 0; for (; n; n »= 1, ++ le) bi[le] = n & 1; bi[le ++] = 0; memset(f, 0, sizeof(f)); memset(g, 0, sizeof(g)); g[0][0] = g[0][1] = 1; for (int i = 1; i < le; ++ i) { g[i][0] = g[i - 1][0] + g[i - 1][1]; g[i][1] = g[i - 1][0]; } f[0] = 1; for (int i = 1; i < le; ++ i) if (bi[i] == 1) { if (bi[i - 1] == 1) f[i] = g[i - 1][0]; else f[i] = f[i - 1]; } else { if (bi[i - 1] == 1) f[i] = f[i - 1] + g[i - 1][0]; else f[i] = f[i - 1]; } return f[le - 1] - 1; }...

June 23, 2015 · 2 min · laekov

bzoj4145.cc

#include #include #include using namespace std; #define pow2(x) (1«(x)) const int maxn = 103; const int maxm = 19; const int maxs = pow2(16) + 3; int n, m, e, d[maxn], c[maxn][maxm], f[maxs], g[maxs]; inline void upMin(int& a, const int& b) { if (a > b) a = b; } int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++ i) { scanf("%d", d + i); for (int j = 0; j < m; ++ j) scanf("%d", c[i] + j); } memset(f, 0x3f, sizeof(f)); f[0] = 0; e = pow2(m); for (int i = 1; i <= n; ++ i) { memset(g, 0x3f, sizeof(int) * e); for (int j = 0; j < m; ++ j) for (int k = e - 1; k >= 0; -- k) if (k & pow2(j)) { upMin(g[k], g[k ^ pow2(j)] + c[i][j]); upMin(g[k], f[k ^ pow2(j)] + d[i] + c[i][j]); } for (int j = 0; j < e; ++ j) upMin(g[j], f[j]); memcpy(f, g, sizeof(int) * e); } printf("%d\n", f[e - 1]); }

June 22, 2015 · 1 min · laekov

bzoj4152.cc

#include #include #include #include using namespace std; struct point { int x, y; void read() { scanf("%d%d", &x, &y); } }; struct edge { int t, v; edge *ne; }; typedef pair <int, int> dpr; const int maxn = 200003; int n, xo[maxn], yo[maxn], d[maxn]; point p[maxn]; edge ebuf_arr[maxn « 2], *ebuf(ebuf_arr), *head[maxn]; inline bool xCmp(const int& a, const int& b) { return p[a]. x < p[b]. x; } inline bool yCmp(const int& a, const int& b) { return p[a]....

June 21, 2015 · 2 min · laekov

bzoj3451.cc

#include #include #include #include using namespace std; #define float_t __float_t typedef double float_t; #define _f (float_t) struct cplx { float_t r, i; cplx() {} cplx(float_t ro, float_t io) { r = ro, i = io; } }; inline cplx operator +(const cplx& a, const cplx& b) { return cplx(a. r + b. r, a. i + b. i); } inline cplx operator -(const cplx& a, const cplx& b) { return cplx(a....

June 17, 2015 · 5 min · laekov