From 06df7f0ac2d7abe8f3d4d0d34da5c93ac05237eb Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 18:42:37 +0800 Subject: [PATCH 1/8] Create 1650.cpp --- QUSTOJ/1650.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 QUSTOJ/1650.cpp diff --git a/QUSTOJ/1650.cpp b/QUSTOJ/1650.cpp new file mode 100644 index 0000000..7ed0eb3 --- /dev/null +++ b/QUSTOJ/1650.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +using namespace std; + +//Kiritow's BIGN (class BigNumber) Written on Nov. 12th, 2015 +//Original Version: Build 1 +class bign +{ +public: + //WARNING: We use public here to reduce time consumed on Interface, although this is not a recommended way. + int data[3000]; + bool more_than_zero; + bign() + { + more_than_zero=true; + } + void set_empty() + { + memset(data,0,sizeof(int)*3000); + } + int lenx() + { + for(int i=3000-1;i>=0;i--) + { + if(data[i]!=0) return i+1; + } + return 0; + } +}; + +char CompareBIGN(bign& a,bign& b) +{ + int lena=a.lenx(); + int lenb=b.lenx(); + if(lenalenb) + { + return '>'; + } + else + { + for(int i=lena-1;i>=0;i--) + { + if(a.data[i]>b.data[i]) + { + return '>'; + } + else if(a.data[i] Date: Wed, 27 Apr 2016 18:43:14 +0800 Subject: [PATCH 2/8] Create 1651.cpp --- QUSTOJ/1651.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 QUSTOJ/1651.cpp diff --git a/QUSTOJ/1651.cpp b/QUSTOJ/1651.cpp new file mode 100644 index 0000000..917f2c8 --- /dev/null +++ b/QUSTOJ/1651.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +using namespace std; + +//Kiritow's BIGN (class BigNumber) Written on Nov. 12th, 2015 +//Original Version: Build 1 (Version 2) +//CCBIGN : from BIGN (Build 1 -version 2) +class ccbign +{ +public: + //WARNING: We use public here to reduce time consumed on Interface, although this is not a recommended way + int data[3000]; + int length; + ccbign() + { + length=0; + } + void set_empty() + { + memset(data,0,sizeof(int)*3000); + } +}; + +int ConvertSTRtoCCBIGN(const char* incstr,ccbign& incbign) +{ + int len=strlen(incstr); + for(int i=0;i0;times--) + { + a.set_empty(); + gets(buff); + int len=ConvertSTRtoCCBIGN(buff,a); + for(int i=0;i Date: Wed, 27 Apr 2016 20:09:53 +0800 Subject: [PATCH 3/8] Create 3947.cpp --- ZOJ/3947.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ZOJ/3947.cpp diff --git a/ZOJ/3947.cpp b/ZOJ/3947.cpp new file mode 100644 index 0000000..1c83639 --- /dev/null +++ b/ZOJ/3947.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +using namespace std; + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int n,tmp,sum; + scanf("%d",&n); + sum=n; + for(int i=0;i Date: Wed, 27 Apr 2016 20:13:21 +0800 Subject: [PATCH 4/8] Create 3936.cpp --- ZOJ/3936.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ZOJ/3936.cpp diff --git a/ZOJ/3936.cpp b/ZOJ/3936.cpp new file mode 100644 index 0000000..d60db38 --- /dev/null +++ b/ZOJ/3936.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +using namespace std; + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int a,b,c,d; + scanf("%d %d %d %d",&a,&b,&c,&d); + printf("%d %d\n",c,b+d); + printf("%d %d\n",a,b+d); + } + return 0; +} From e85c5cce682c1036e2ce6b40a8cdf2f800abe6f2 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 20:30:36 +0800 Subject: [PATCH 5/8] From http://blog.csdn.net/qq_33765907/article/details/51228610 --- ZOJ/3937_csdn.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 ZOJ/3937_csdn.cpp diff --git a/ZOJ/3937_csdn.cpp b/ZOJ/3937_csdn.cpp new file mode 100644 index 0000000..5599d4e --- /dev/null +++ b/ZOJ/3937_csdn.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; +typedef long long LL; + +class Solution { + static const int MAXN = 100000 + 10; + static const LL inf = 1ll << 60; + vector G[MAXN]; + int w[MAXN], n; + + struct Line {// m * x + b + LL m, b; + double inter(const Line &r) const { + return (r.b - b) / (m - r.m); + } + inline LL eval(LL x) {return m * x + b;} + } Q[MAXN];a + + int rt, mins, total, top; + int vs[MAXN], sz[MAXN], dep[MAXN]; + LL val[MAXN], ps[MAXN], ret; + + void getCenter(int u, int f = -1) { + int mx = 0; sz[u] = 1; + for (auto &v: G[u]) if (v != f && !vs[v]) { + getCenter(v, u); sz[u] += sz[v]; + mx = max(mx, sz[v]); + } + mx = max(mx, total - sz[u]); + if (mx < mins) mins = mx, rt = u; + } + int dfs1(int u, int d = 1) { + ret = max(ret, val[d]); + for (auto &v: G[u]) if (!vs[v] && u > v) { + ps[v] = ps[u] + w[v]; + val[d + 1] = val[d] + ps[v]; + return dfs1(v, d + 1) + 1; + } + return 1; + } + void dfs2(int u, int d = 0, LL sum = 0) { + sum += 1ll * d * w[u]; + // max(ps[u] * m + b + sum) + int left = 0, right = top - 2; + while (left < right) { + int mid = (left + right) >> 1; + if (Q[mid].eval(ps[u]) >= Q[mid + 1].eval(ps[u])) right = mid; + else left = mid + 1; + } + ret = max(ret, Q[left].eval(ps[u]) + sum); + if (left + 1 < top) ret = max(ret, Q[left + 1].eval(ps[u]) + sum); + for (auto &v: G[u]) if (!vs[v] && u < v) { + ps[v] = ps[u] + w[v]; + dfs2(v, d + 1, sum); + } + } + void solve(int u, int _tot) { + total = _tot; mins = _tot * 2; + getCenter(u); u = rt; vs[u] = 1; getCenter(u); + val[1] = ps[u] = w[u]; + int md = dfs1(u); + top = 0; + for (int i = 1; i <= md; ++i) { + Line now = (Line){i, val[i]}; + while (top >= 2 && Q[top - 2].inter(Q[top - 1]) >= Q[top - 1].inter(now)) --top; + Q[top++] = now; + } + ps[u] = 0; dfs2(u); + for (int i = 0; i <= md; ++i) val[i] = -inf; + for (auto &v: G[u]) if (!vs[v]) { + solve(v, sz[v]); + } + } + +public: + void run() { + scanf("%d", &n); + for (int i = 0; i < n; ++i) { + scanf("%d", w + i); G[i].clear(); + } + for (int i = 1; i < n; ++i) { + int x; scanf("%d", &x); --x; + G[x].push_back(i); + G[i].push_back(x); + } + ret = 0; + for (int i = 0; i < n; ++i) val[i] = -inf; + memset(vs, 0, sizeof(vs[0]) * n); + solve(0, n); + printf("%lld\n", ret); + } +} sol; + +int main() { + int T; scanf("%d", &T); + for (int cas = 1; cas <= T; ++cas) sol.run(); + return 0; +} From dfb763565fcaf369036f8c46b87fd3444cf9e206 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 20:31:32 +0800 Subject: [PATCH 6/8] From http://blog.csdn.net/qq_33765907/article/details/51228610 --- ZOJ/3938_csdn.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ZOJ/3938_csdn.cpp diff --git a/ZOJ/3938_csdn.cpp b/ZOJ/3938_csdn.cpp new file mode 100644 index 0000000..c2e9989 --- /dev/null +++ b/ZOJ/3938_csdn.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; +typedef pair PII; + +vector res; +int b[5][5], a[5]; + +int main() { + int T; scanf("%d", &T); + for (int cas = 1; cas <= T; ++cas) { + int r[5]; + for (int i = 0; i < 5; ++i) { + for (int j = 0; j < 5; ++j) { + cin >> b[i][j]; + } + } + // stage 1 + int *x = b[0], d = x[0]; + if (d <= 2) r[0] = 2; + else r[0] = d; + // stage 2 + x = b[1], d = x[0]; + for (int i = 1; i < 5; ++i) a[x[i]] = i; + if (d == 1) r[1] = a[4]; + else if (d == 3) r[1] = 1; + else r[1] = r[0]; + // stage 3 + x = b[2], d = x[0]; + for (int i = 1; i < 5; ++i) a[x[i]] = i; + if (d == 1) r[2] = a[b[1][r[1]]]; + else if (d == 2) r[2] = a[b[0][r[0]]]; + else if (d == 4) r[2] = a[4]; + else r[2] = d; + // stage 4 + x = b[3], d = x[0]; + if (d == 1) r[3] = r[0]; + else if (d == 2) r[3] = 1; + else r[3] = r[1]; + // stage 5 + x = b[4], d = x[0]; + for (int i = 1; i < 5; ++i) a[x[i]] = i; + if (d <= 2) r[4] = a[b[d - 1][r[d - 1]]]; + else r[4] = a[b[6 - d][r[6 - d]]]; + for (int i = 0; i < 5; ++i) { + cout << r[i] << " " << b[i][r[i]] << endl; + } + } + return 0; +} From 0937f099e8c5556581345e197c690e4c2d75fba9 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 20:32:06 +0800 Subject: [PATCH 7/8] Create 3939.cpp --- ZOJ/3939.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ZOJ/3939.cpp diff --git a/ZOJ/3939.cpp b/ZOJ/3939.cpp new file mode 100644 index 0000000..bda31ba --- /dev/null +++ b/ZOJ/3939.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; + +vector> p; + +int day(int y, int m, int d) { + int tm = m >= 3 ? (m - 2) : (m + 10); + int ty = m >= 3 ? y : (y - 1); + return (ty + ty / 4 - ty / 100 + ty / 400 + (int)(2.6 * tm - 0.2) + d) % 7; +} + +void run() { + int y, m, d, n; cin >> y >> m >> d >> n; + y -= 1753; n += y / 2800 * p.size(); + y %= 2800; + n += lower_bound(p.begin(), p.end(), make_tuple(y, m, d)) - p.begin() - 1; + auto res = p[n % p.size()]; + y = get<0>(res); + m = get<1>(res); + d = get<2>(res); + y += n / p.size() * 2800 + 1753; + cout << y << " " << m << " " << d << endl; +} + +int main() { + cerr << day(1753, 1, 1) << endl; + for (int y = 0; y < 2800; ++y) { + for (int m = 1; m <= 12; ++m) { + if (day(y + 1753, m, 1) == 1) p.push_back(make_tuple(y, m, 1)); + if (day(y + 1753, m, 11) == 1) p.push_back(make_tuple(y, m, 11)); + if (day(y + 1753, m, 21) == 1) p.push_back(make_tuple(y, m, 21)); + } + } + int T; scanf("%d", &T); + for (int cas = 1; cas <= T; ++cas) run(); + return 0; +} From 1d9e7f3632c4195560aafa6043a0531aefa47f83 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 20:32:34 +0800 Subject: [PATCH 8/8] From http://blog.csdn.net/qq_33765907/article/details/51228610 --- ZOJ/{3939.cpp => 3939_csdn.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ZOJ/{3939.cpp => 3939_csdn.cpp} (100%) diff --git a/ZOJ/3939.cpp b/ZOJ/3939_csdn.cpp similarity index 100% rename from ZOJ/3939.cpp rename to ZOJ/3939_csdn.cpp