From 3fc96547c2d42f8e26fca1b67dd750d7e852be31 Mon Sep 17 00:00:00 2001 From: TooYoungTooSimp <6648049+TooYoungTooSimp@users.noreply.github.com> Date: Fri, 1 Nov 2019 09:07:08 +0800 Subject: [PATCH] Fri, 01 Nov 2019 09:07:08 GMT --- .vscode/launch.json | 35 ------------ .vscode/settings.json | 68 ------------------------ .vscode/tasks.json | 18 ------- Article6/Water/poj3299.cpp | 21 ++++++++ C332851/A.cpp | 67 +++++++++++++++++++++++ C332851/F.cpp | 26 +++++++++ C332851/K.cpp | 47 ++++++++++++++++ C332851/L.cpp | 32 +++++++++++ C333519/H.cpp | 31 +++++++++++ C333519/I.cpp | 23 ++++++++ C333519/J.cpp | 27 ++++++++++ C333519/K.cpp | 26 +++++++++ C335737/A.cpp | 20 +++++++ C335737/B.cpp | 42 +++++++++++++++ C335737/D.cpp | 24 +++++++++ C335737/M.cpp | 87 ++++++++++++++++++++++++++++++ C338970/B.cpp | 63 ++++++++++++++++++++++ C338970/H.cpp | 36 +++++++++++++ C338970/I.cpp | 91 +++++++++++++++++++++++++++++++ C338970/K.cpp | 37 +++++++++++++ C339575/I.cpp | 40 ++++++++++++++ atcoder/abc108c.cpp | 16 ++++++ atcoder/abc109c.cpp | 18 +++++++ atcoder/abc110c.cpp | 18 +++++++ atcoder/abc111c.cpp | 31 +++++++++++ atcoder/abc112c.cpp | 28 ++++++++++ atcoder/abc113c.cpp | 25 +++++++++ atcoder/abc114c.cpp | 28 ++++++++++ atcoder/abc115c.cpp | 18 +++++++ atcoder/abc116c.cpp | 12 +++++ atcoder/abc117c.cpp | 21 ++++++++ java/1.java | 20 +++++++ nw/sock/client.py | 11 ++++ nw/sock/server.py | 18 +++++++ tmp/1.cpp | 26 +++++++++ tmp/K.cpp | 106 +++++++++++++++++++++++++++++++++++++ tmp/test1.ipynb | 49 +++++++++++++++++ tmpl.cpp | 21 ++++++++ tmpl.h | 32 ----------- 39 files changed, 1206 insertions(+), 153 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json create mode 100644 Article6/Water/poj3299.cpp create mode 100644 C332851/A.cpp create mode 100644 C332851/F.cpp create mode 100644 C332851/K.cpp create mode 100644 C332851/L.cpp create mode 100644 C333519/H.cpp create mode 100644 C333519/I.cpp create mode 100644 C333519/J.cpp create mode 100644 C333519/K.cpp create mode 100644 C335737/A.cpp create mode 100644 C335737/B.cpp create mode 100644 C335737/D.cpp create mode 100644 C335737/M.cpp create mode 100644 C338970/B.cpp create mode 100644 C338970/H.cpp create mode 100644 C338970/I.cpp create mode 100644 C338970/K.cpp create mode 100644 C339575/I.cpp create mode 100644 atcoder/abc108c.cpp create mode 100644 atcoder/abc109c.cpp create mode 100644 atcoder/abc110c.cpp create mode 100644 atcoder/abc111c.cpp create mode 100644 atcoder/abc112c.cpp create mode 100644 atcoder/abc113c.cpp create mode 100644 atcoder/abc114c.cpp create mode 100644 atcoder/abc115c.cpp create mode 100644 atcoder/abc116c.cpp create mode 100644 atcoder/abc117c.cpp create mode 100644 java/1.java create mode 100644 nw/sock/client.py create mode 100644 nw/sock/server.py create mode 100644 tmp/1.cpp create mode 100644 tmp/K.cpp create mode 100644 tmp/test1.ipynb create mode 100644 tmpl.cpp delete mode 100644 tmpl.h diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 205059d..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Terminal (integrated)", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - }, - { - "name": "(gdb) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/a.out", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": true, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "build current" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 63ed336..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "python.formatting.provider": "yapf", - "files.associations": { - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "cfenv": "cpp", - "charconv": "cpp", - "chrono": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "csetjmp": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cuchar": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "forward_list": "cpp", - "list": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "fstream": "cpp", - "functional": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "numeric": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "scoped_allocator": "cpp", - "shared_mutex": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "thread": "cpp", - "type_traits": "cpp", - "tuple": "cpp", - "typeindex": "cpp", - "typeinfo": "cpp", - "utility": "cpp", - "valarray": "cpp" - } -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 48d1d7f..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "build current", - "type": "shell", - "command": "g++", - "args": [ - "-std=c++2a", - "-Wall", - "-g", - "${file}" - ] - } - ] -} \ No newline at end of file diff --git a/Article6/Water/poj3299.cpp b/Article6/Water/poj3299.cpp new file mode 100644 index 0000000..57176f8 --- /dev/null +++ b/Article6/Water/poj3299.cpp @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +int main() +{ + int a[3]; + CLR(a); + return 0; +} \ No newline at end of file diff --git a/C332851/A.cpp b/C332851/A.cpp new file mode 100644 index 0000000..c9106fe --- /dev/null +++ b/C332851/A.cpp @@ -0,0 +1,67 @@ +#include +using namespace std; +typedef long long ll; +const double eps = 1e-8; +int cmp(double x) +{ + if (x > eps) + return 1; + if (x < -eps) + return -1; + return 0; +} +typedef struct +{ + double x, y; +} Base2D, Point, Vector; +typedef const Point &CBase2DRef; +typedef const Point &CPointRef; +typedef const Vector &CVectorRef; +inline Base2D operator+(CBase2DRef l, CBase2DRef r) { return {l.x + r.x, l.y + r.y}; } +inline Base2D operator-(CBase2DRef l, CBase2DRef r) { return {l.x - r.x, l.y - r.y}; } +inline Base2D operator*(CBase2DRef l, double r) { return {l.x * r, l.y * r}; } +inline double cross(CVectorRef l, CVectorRef r) { return l.x * r.y - l.y * r.x; } +inline double square(double x) { return x * x; } +inline double dis2(CPointRef l, CPointRef r) { return square(r.x - l.x) + square(r.y - l.y); } +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + double ox, oy, r, ax, ay, vx, vy, bx, by; + scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf", &ox, &oy, &r, &ax, &ay, &vx, &vy, &bx, &by); + Vector dir = {vx, vy}; + Point o = {ox, oy}, a = {ax, ay}, b = {bx, by}; + bool flag = false; + Vector oa = a - o, ba = a - b, bo = o - b; + double fx = (bx - ax) / vx, fy = (by - ay) / vy; + if (cmp(fx) == 1 && cmp(fx - fy) == 0) // Hit + { + if (cross(oa, dir) == 1 || cmp(cross(ba, bo)) <= 0 || abs(cross(oa, bo) / sqrt(dis2(ba, {0, 0}))) >= r) + flag = true; + } + else + { + double dis = abs(cross(oa, oa + dir) / sqrt(dis2(dir, {0, 0}))); + if (dis <= r) + { + // get first intersect + double disInCircle = sqrt(r * r - dis * dis); + double disOutCircle = sqrt(dis2(oa, {0, 0}) - dis * dis) - disInCircle; + double scale = disOutCircle / sqrt(dis2(dir, {0, 0})); + Point intersect = a + dir * scale; + // mirror the line + double A = intersect.y - o.y, B = o.x - intersect.x, C = intersect.x * o.y - o.x * intersect.y; + double k = -2 * (A * a.x + B * a.y + C) / (A * A + B * B); + Point am = {a.x + k * A, a.y + k * B}; + Vector dir2 = am - intersect; + fx = (b.x - intersect.x) / dir2.x, fy = (b.y - intersect.y) / dir2.y; + if (cmp(fx) == 1 && cmp(fx - fy) == 0) + flag = true; + } + } + printf("Case #%d: %s\n", t, flag ? "Yes" : "No"); + } + return 0; +} \ No newline at end of file diff --git a/C332851/F.cpp b/C332851/F.cpp new file mode 100644 index 0000000..4d9f1b4 --- /dev/null +++ b/C332851/F.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +typedef long long ll; +char s[1050]; +int pre[256]; +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + scanf("%s", s); + memset(pre, -1, sizeof(pre)); + unsigned ans = -1; + int n = strlen(s); + for (int i = 0; i < n; i++) + { + if (pre[s[i]] != -1) + ans = min(ans, i - pre[s[i]]); + pre[s[i]] = i; + } + + printf("Case #%d: %d\n", t, ans); + } + return 0; +} \ No newline at end of file diff --git a/C332851/K.cpp b/C332851/K.cpp new file mode 100644 index 0000000..82d4b74 --- /dev/null +++ b/C332851/K.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +typedef long long ll; +const int N = 1e5 + 50; +char a[N]; +vector v; +inline ll square(ll x) { return x * x; } +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + v.clear(); + scanf("%s", a); + int n = strlen(a); + int curLen = 1; + for (int i = 1; i < n; i++) + { + if (a[i - 1] == a[i]) + curLen++; + else + v.push_back(curLen), curLen = 1; + } + v.push_back(curLen); + /*for (int i : v) + cout << i << " "; + cout << endl;*/ + ll ans_base = accumulate(v.begin(), v.end(), 0ll, [](ll pr, ll x) { + return pr + x * x; + }); + ll ans = ans_base; + if (v[0] == 1) + ans = max(ans, ans_base - 1 - square(v[1]) + square(1 + v[1])); + if (v[v.size() - 1] == 1) + ans = max(ans, ans_base - 1 - square(v[v.size() - 2]) + square(1 + v[v.size() - 2])); + for (int i = 1; i < v.size() - 1; i++) + if (v[i] == 1) + ans = max(ans, ans_base - 1 - square(v[i - 1]) - square(v[i + 1]) + square(v[i - 1] + 1 + v[i + 1])); + for (int i = 1; i < v.size(); i++) + ans = max(ans, ans_base - square(v[i - 1]) - square(v[i]) + square(v[i - 1] + 1) + square(v[i] - 1)); + for (int i = 1; i < v.size(); i++) + ans = max(ans, ans_base - square(v[i - 1]) - square(v[i]) + square(v[i - 1] - 1) + square(v[i] + 1)); + printf("Case #%d: %lld\n", t, ans); + } + return 0; +} \ No newline at end of file diff --git a/C332851/L.cpp b/C332851/L.cpp new file mode 100644 index 0000000..ad3f4ff --- /dev/null +++ b/C332851/L.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +typedef long long ll; +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +ll calc(ll x, ll y) +{ + if (x > y) + swap(x, y); + ll ans = 1; + for (ll i = 1; i * i <= y; i++) + if (y % i == 0) + { + if (y == i * (1 + x / gcd(x, i))) + ans += calc(x, i); + if (i * i != y) + { + ll j = y / i; + if (y == j * (1 + x / gcd(x, j))) + ans += calc(x, j); + } + } + //printf("calc(%lld, %lld) = %lld\n", x, y, ans); + return ans; +} +int main() +{ + int T, x, y; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + scanf("%d%d", &x, &y), printf("Case #%d: %lld\n", t, calc(x, y)); + return 0; +} \ No newline at end of file diff --git a/C333519/H.cpp b/C333519/H.cpp new file mode 100644 index 0000000..6a2b82c --- /dev/null +++ b/C333519/H.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +typedef long long ll; +const int N = 1e5 + 50; +ll f[N]; +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + printf("Case #%d:\n", t); + int q, m, op, x; + scanf("%d%d", &q, &m); + ll ans = 1; + for (int i = 1; i <= q; i++) + { + scanf("%d%d", &op, &x); + if (op == 1) + ans = ans * (f[i] = x) % m; + else + { + ans = f[x] = f[i] = 1; + for (int j = 1; j < i; j++) + ans = ans * f[j] % m; + } + printf("%lld\n", ans); + } + } + return 0; +} \ No newline at end of file diff --git a/C333519/I.cpp b/C333519/I.cpp new file mode 100644 index 0000000..da0c5b3 --- /dev/null +++ b/C333519/I.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +typedef long long ll; +inline double sq(double x) { return x * x; } +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + double ax, ay, bx, by, cx, cy; + scanf("%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &cx, &cy); + double mx = (bx + cx) / 2, my = (by + cy) / 2; + double ac = sqrt(sq(ax - cx) + sq(ay - cy)); + double bc = sqrt(sq(bx - cx) + sq(by - cy)); + double am = sqrt(sq(ax - mx) + sq(ay - my)); + double r = bc * ac / am / 2; + double alpha = asin(am / ac) * 2; + double arc = alpha * r; + printf("Case #%d: %.4lf\n", t, am + arc); + } + return 0; +} \ No newline at end of file diff --git a/C333519/J.cpp b/C333519/J.cpp new file mode 100644 index 0000000..de09869 --- /dev/null +++ b/C333519/J.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +typedef long long ll; +const int N = 105; +int L[N], R[N]; +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + int n, a, b, l; + scanf("%d%d%d%d", &n, &a, &b, &l); + for (int i = 0; i < n; i++) + scanf("%d%d", L + i, R + i); + ll cur = 0, ans = 0; + int pos = 0; + for (int i = 0; i < n; i++) + { + cur += b * (L[i] - pos) - a * (R[i] - L[i]); + ans = max(ans, -cur); + pos = R[i]; + } + printf("Case #%d: %lld\n", t, ans); + } + return 0; +} \ No newline at end of file diff --git a/C333519/K.cpp b/C333519/K.cpp new file mode 100644 index 0000000..9494ddd --- /dev/null +++ b/C333519/K.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +typedef long long ll; +ll fpow(ll a, ll b, ll m) +{ + ll r = 1; + for (; b; b >>= 1, a = a * a % m) + if (b & 1) + r = r * a % m; + return r; +} +int main() +{ + ll c, k1, k2, b1; + for (int t = 1; ~scanf("%lld%lld%lld%lld", &c, &k1, &b1, &k2); t++) + { + printf("Case #%d:\n", t); + bool flag = 0; + for (ll i = 1, a, b; i < c; i++) + if (fpow(a = i, k1, c) == fpow(b = c - fpow(a, k1 + b1, c), k2, c)) + printf("%lld %lld\n", a, b), flag = true; + if (!flag) + puts("-1"); + } + return 0; +} \ No newline at end of file diff --git a/C335737/A.cpp b/C335737/A.cpp new file mode 100644 index 0000000..360fdbc --- /dev/null +++ b/C335737/A.cpp @@ -0,0 +1,20 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +int main() +{ + + return 0; +} \ No newline at end of file diff --git a/C335737/B.cpp b/C335737/B.cpp new file mode 100644 index 0000000..ac3b2cd --- /dev/null +++ b/C335737/B.cpp @@ -0,0 +1,42 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +char ss[505][2050]; +bool vis[505]; +int main() +{ + int T, n; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + CLR(vis); + scanf("%d", &n); + for (int i = 1; i <= n; i++) + scanf("%s", ss[i]); + int ans = -1; + for (int i = 1; i <= n; i++) + for (int j = 1; j < i; j++) + { + if (vis[j]) + continue; + if (strstr(ss[i], ss[j]) != nullptr) + vis[j] = true; + else + ans = i; + } + printf("Case #%d: %d\n", t, ans); + } + return 0; +} \ No newline at end of file diff --git a/C335737/D.cpp b/C335737/D.cpp new file mode 100644 index 0000000..6c7c672 --- /dev/null +++ b/C335737/D.cpp @@ -0,0 +1,24 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +int main() +{ + int T, n, a, b; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + scanf("%d%d%d", &n, &a, &b), printf("Case #%d: %s\n", t, (n / gcd(b, a) & 1) ? "Yuwgna" : "Iaka"); + return 0; +} \ No newline at end of file diff --git a/C335737/M.cpp b/C335737/M.cpp new file mode 100644 index 0000000..70441af --- /dev/null +++ b/C335737/M.cpp @@ -0,0 +1,87 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +const int maxn = 1e5 + 5; +int n, m; +int t[maxn]; +vector gid[maxn]; +vector grp[maxn]; +ll dis1[maxn], dis2[maxn]; +void dijkstra(int S, ll *dis) +{ + struct heap_node + { + int u; + ll d; + OPL(heap_node, rhs) { return d > rhs.d; } + }; + priority_queue H; + H.push({S, dis[S] = 0}); + for (heap_node cur; !H.empty(); H.pop()) + for (int g : gid[(cur = H.top()).u]) + for (int to : grp[g]) + if (dis[to] > dis[cur.u] + t[g]) + H.push({to, dis[to] = dis[cur.u] + t[g]}); +} +int main() +{ + + int T; + cin >> T; + for (int _ = 1; _ <= T; _++) + { + scanf("%d%d", &n, &m); + memset(dis1, 0x3f, sizeof(ll) * (n + 2)); + memset(dis2, 0x3f, sizeof(ll) * (n + 2)); + for (int i = 1; i <= n; i++) + gid[i].clear(); + for (int i = 0, cnt; i < m; i++) + { + grp[i].clear(); + scanf("%d%d", t + i, &cnt); + for (int j = 0, x; j < cnt; j++) + { + scanf("%d", &x); + gid[x].push_back(i); + grp[i].push_back(x); + } + } + dijkstra(1, dis1); + dijkstra(n, dis2); + ll mx = LLONG_MAX; + for (int i = 1; i <= n; i++) + mx = min(mx, max(dis1[i], dis2[i])); + IFD + { + for (int i = 1; i <= n; i++) + printf("%lld%c", dis1[i], " \n"[i == n]); + for (int i = 1; i <= n; i++) + printf("%lld%c", dis2[i], " \n"[i == n]); + } + printf("Case #%d: ", _); + ll inf = *dis1 >> 1; + if (mx >= inf) + puts("Evil John"); + else + { + printf("%lld\n", mx); + for (int i = 1; i <= n; i++) + if (mx == max(dis1[i], dis2[i])) + printf("%d ", i); + putchar('\n'); + } + } + return 0; +} \ No newline at end of file diff --git a/C338970/B.cpp b/C338970/B.cpp new file mode 100644 index 0000000..4ef7cd7 --- /dev/null +++ b/C338970/B.cpp @@ -0,0 +1,63 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +int T, n, m, k; +int col[26], a[6][6]; +bool flag = false; +void dfs(int st) +{ + if (st == -1) + { + flag = true; + return; + } + for (int i = 0; i < k; i++) + if ((st + 2) / 2 < col[i]) + return; + int x = st / m, y = st % m; + for (int i = 0; i < k; i++) + if (col[i] && a[x + 1][y] != i && a[x][y + 1] != i) + { + col[a[x][y] = i]--; + dfs(st - 1); + if (flag) + return; + col[i]++; + a[x][y] = -1; + } +} +int main() +{ + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + NE1(a), flag = false; + scanf("%d%d%d", &n, &m, &k); + for (int i = 0; i < k; i++) + scanf("%d", col + i); + dfs(n * m - 1); + printf("Case #%d:\n", t); + if (flag) + { + puts("YES"); + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + printf("%d%c", a[i][j] + 1, " \n"[j == m - 1]); + } + else + puts("NO"); + } + return 0; +} \ No newline at end of file diff --git a/C338970/H.cpp b/C338970/H.cpp new file mode 100644 index 0000000..fb3628f --- /dev/null +++ b/C338970/H.cpp @@ -0,0 +1,36 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; + +const int N = 1 << 20; +int a[42]; +ll f[42][N | 1]; +int main() +{ + **f = 1; + int T, n, m; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + scanf("%d%d", &n, &m); + for (int i = 1; i <= n; i++) + scanf("%d", a + i); + for (int i = 1; i <= n; i++) + for (int j = 0; j < N; j++) + f[i][j] = f[i - 1][j ^ a[i]] + f[i - 1][j]; + printf("Case #%d: %lld\n", t, accumulate(f[n] + m, f[n] + N, 0ll)); + } + return 0; +} \ No newline at end of file diff --git a/C338970/I.cpp b/C338970/I.cpp new file mode 100644 index 0000000..afb79dc --- /dev/null +++ b/C338970/I.cpp @@ -0,0 +1,91 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +template +using enable_if_arithmetic = typename enable_if::value>::type; +template +using enable_if_integral = typename enable_if::value>::type; + +constexpr double eps = 1e-8; +int sgn(double x) +{ + if (x > eps) + return 1; + if (x < -eps) + return -1; + return 0; +} + +template > +struct Point +{ + T x, y; + Point OPX(-, Point, rhs) const { return {x - rhs.x, y - rhs.y}; } + T OPX(*, Point, rhs) const { return x * rhs.x + y * rhs.y; } + T OPX (^, Point, rhs) const { return x * rhs.y - y * rhs.x; } + T len2() const { return x * x + y * y; } + double len() const { return sqrt(len2()); } +}; +template +struct Line +{ + Point s, e; + T len2() const { return (s - e).len2(); } + double len() const { return (s - e).len(); } + bool contains(CRP(Point, p)) const { return sgn((s - p) ^ (e - p)) == 0 && sgn((s - p) * (e - p)) <= 0; } +}; +template +struct Circle +{ + Point c; + T r; +}; +#define Point Point +#define norm len +const double pi = acos(-1); +double area(Point ap, double ra, Point bp, double rb) +{ + double a = (ap - bp).norm(), b = ra, c = rb; + if (b < eps || c < eps) + return 0; + if (a < rb - ra + eps) + return pi * ra * ra; + if (a < ra - rb + eps) + return pi * rb * rb; + if (a < eps) + return pi * sqrt(min(ra, rb)); + if (a > ra + rb - eps) + return 0; + double cta1 = acos((a * a + b * b - c * c) / 2 / (a * b)); + double cta2 = acos((a * a + c * c - b * b) / 2 / (a * c)); + double s1 = ra * ra * cta1 - ra * ra * sin(cta1) * (a * a + b * b - c * c) / 2 / (a * b); + double s2 = rb * rb * cta2 - rb * rb * sin(cta2) * (a * a + c * c - b * b) / 2 / (a * c); + return s1 + s2; +} +int main() +{ + int T; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + double r, R; + Point p1, p2; + scanf("%lf%lf%lf%lf%lf%lf", &r, &R, &p1.x, &p1.y, &p2.x, &p2.y); + printf("Case #%d: %lf\n", t, + area(p1, R, p2, R) - area(p1, r, p2, R) - area(p1, R, p2, r) + area(p1, r, p2, r)); + } + return 0; +} \ No newline at end of file diff --git a/C338970/K.cpp b/C338970/K.cpp new file mode 100644 index 0000000..b414ee7 --- /dev/null +++ b/C338970/K.cpp @@ -0,0 +1,37 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +const int N = 1e6 + 60; +int a[N]; +int main() +{ + int T, n; + scanf("%d", &T); + for (int t = 1; t <= T; t++) + { + scanf("%d", &n); + for (int i = 1; i <= n; i++) + scanf("%d", a + i); + int mn = INT_MAX, ans = 0; + for (int i = n; i; i--) + if (a[i] < mn) + mn = a[i]; + else + ans++; + printf("Case #%d: %d\n", t, ans); + } + return 0; +} \ No newline at end of file diff --git a/C339575/I.cpp b/C339575/I.cpp new file mode 100644 index 0000000..5b5101b --- /dev/null +++ b/C339575/I.cpp @@ -0,0 +1,40 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(t, x)) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef int64_t ll, i64; +typedef uint64_t ull, u64; +const int N = 1005 * 1005; +const double eps = 1e-8; +int a[1605], x[45]; +int main() +{ + int T, n; + double p; + scanf("%d", &T); + while (T--) + { + scanf("%d%lf", &n, &p); + for (int i = 1; i <= n; i++) + cin >> x[i]; + a[0] = 0; + int co = 1; + for (int i = 0; i <= n; i++) + for (int j = i + 1; j <= n; j++) + a[co++] = x[i] + x[j]; + sort(a, a + co); + n = (1.0 - p < eps) ? n : (int)(p * pow(2, n)); + cout << a[n - 1] << endl; + } + return 0; +} diff --git a/atcoder/abc108c.cpp b/atcoder/abc108c.cpp new file mode 100644 index 0000000..e6b691f --- /dev/null +++ b/atcoder/abc108c.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +const int N = 1e5 + 50; +int a[N]; +int main() +{ + int n, k; + scanf("%d%d", &n, &k); + for (int i = 0; i < n; i++) + scanf("%d", a + i); + int ans = 0x3f3f3f3f; + for (int i = 0; i <= n - k; i++) + ans = min(ans, min(abs(a[i]) + a[i + k - 1] - a[i], abs(a[i + k - 1]) + a[i + k - 1] - a[i])); + printf("%d", ans); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc109c.cpp b/atcoder/abc109c.cpp new file mode 100644 index 0000000..a1ef0f7 --- /dev/null +++ b/atcoder/abc109c.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +const int N = 1e5 + 50; +typedef long long ll; +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +int a[N]; +int main() +{ + int n, x; + scanf("%d%d", &n, &x); + for (int i = 0; i < n; i++) + scanf("%d", a + i), a[i] = abs(a[i] - x); + int g = *a; + for (int i = 0; i < n; i++) + g = gcd(g, a[i]); + printf("%d", g); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc110c.cpp b/atcoder/abc110c.cpp new file mode 100644 index 0000000..7cec19c --- /dev/null +++ b/atcoder/abc110c.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +typedef long long ll; +const int N = 2e5 + 50; +char s[N], t[N]; +char mp1[256], mp2[256]; +int main() +{ + scanf("%s%s", s, t); + for (char *ps = s, *pt = t; *ps; ps++, pt++) + { + if (mp1[*ps] == 0 && mp2[*pt] == 0) + mp1[*ps] = *pt, mp2[*pt] = *ps; + if (mp1[*ps] != *pt || mp2[*pt] != *ps) + return puts("No"), 0; + } + return puts("Yes"), 0; +} \ No newline at end of file diff --git a/atcoder/abc111c.cpp b/atcoder/abc111c.cpp new file mode 100644 index 0000000..9c50378 --- /dev/null +++ b/atcoder/abc111c.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +typedef long long ll; +const int N = 1e5 + 50; +int a[N], cnt1[N], cnt2[N]; +int main() +{ + int n; + scanf("%d", &n); + for (int i = 0; i < n; i++) + scanf("%d", a + i); + for (int i = 0; i < n; i += 2) + cnt1[a[i]]++; + for (int i = 1; i < n; i += 2) + cnt2[a[i]]++; + vector> v1(n), v2(n); + v1.push_back({0, 0}), v2.push_back({0, 0}); + for (int i = 0; i < N; i++) + if (cnt1[i]) + v1.push_back({cnt1[i], i}); + for (int i = 0; i < N; i++) + if (cnt2[i]) + v2.push_back({cnt2[i], i}); + sort(v1.begin(), v1.end(), greater>()); + sort(v2.begin(), v2.end(), greater>()); + if (v1[0].second != v2[0].second) + printf("%d", n - v1[0].first - v2[0].first); + else + printf("%d", min(n - v1[0].first - v2[1].first, n - v1[1].first - v2[0].first)); + return 0; +} diff --git a/atcoder/abc112c.cpp b/atcoder/abc112c.cpp new file mode 100644 index 0000000..8f9800e --- /dev/null +++ b/atcoder/abc112c.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +struct +{ + int x, y, h; +} a[105]; +int main() +{ + int n; + scanf("%d", &n); + for (int i = 0; i < n; i++) + scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].h); + for (int i = 0; i < n && a->h == 0; i++) + if (a[i].h) + iter_swap(a + i, a); + for (int i = 0; i <= 100; i++) + for (int j = 0; j <= 100; j++) + { + int pre = a->h + abs(i - a->x) + abs(j - a->y); + bool flag = true; + for (int k = 0; k < n && flag; k++) + if (max(pre - abs(i - a[k].x) - abs(j - a[k].y), 0) != a[k].h) + flag = false; + if (flag) + return printf("%d %d %d", i, j, pre), 0; + } + return 0; +} \ No newline at end of file diff --git a/atcoder/abc113c.cpp b/atcoder/abc113c.cpp new file mode 100644 index 0000000..a663d48 --- /dev/null +++ b/atcoder/abc113c.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +const int N = 1e5 + 50; +struct +{ + int p, y; +} a[N]; +vector> v[N]; +int main() +{ + int n, m; + scanf("%d%d", &n, &m); + for (int i = 0; i < m; i++) + scanf("%d%d", &a[i].p, &a[i].y); + for (int i = 0; i < m; i++) + v[a[i].p].push_back({a[i].y, i}); + for (int i = 1; i <= n; i++) + sort(v[i].begin(), v[i].end()); + for (int i = 1; i <= n; i++) + for (int j = 0; j < v[i].size(); j++) + a[v[i][j].second].y = j + 1; + for (int i = 0; i < m; i++) + printf("%06d%06d\n", a[i].p, a[i].y); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc114c.cpp b/atcoder/abc114c.cpp new file mode 100644 index 0000000..301aa57 --- /dev/null +++ b/atcoder/abc114c.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +typedef long long ll; +int m[] = {0, 3, 5, 7}; +int main() +{ + ll n; + scanf("%lld", &n); + int cnt = 0; + for (int i = 0;; i++) + { + ll cur = 0; + bool b[4] = {0}; + char buf[20]; + int l = 0, x = i; + do + buf[l++] = x & 3, x >>= 2; + while (x); + for (int j = l - 1; j >= 0; j--) + cur = cur * 10 + m[buf[j]], b[buf[j]] = true; + if (cur > n) + break; + if (!b[0] && b[1] && b[2] && b[3]) + cnt++; + } + printf("%d", cnt); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc115c.cpp b/atcoder/abc115c.cpp new file mode 100644 index 0000000..3a38da5 --- /dev/null +++ b/atcoder/abc115c.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +typedef long long ll; +const int N = 1e5 + 50; +int a[N]; +int main() +{ + int k, n; + scanf("%d%d", &n, &k); + for (int i = 0; i < n; i++) + scanf("%d", a + i); + sort(a, a + n); + int ans = a[n - 1] - a[0]; + for (int i = k - 1; i < n; i++) + ans = min(ans, a[i] - a[i - k + 1]); + printf("%d", ans); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc116c.cpp b/atcoder/abc116c.cpp new file mode 100644 index 0000000..5fc430a --- /dev/null +++ b/atcoder/abc116c.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +typedef long long ll; +int main() +{ + int n, x, pre = 0, ans = 0; + scanf("%d", &n); + for (int i = 0; i < n; i++, pre = x) + scanf("%d", &x), ans += max(0, x - pre); + printf("%d", ans); + return 0; +} \ No newline at end of file diff --git a/atcoder/abc117c.cpp b/atcoder/abc117c.cpp new file mode 100644 index 0000000..8962e32 --- /dev/null +++ b/atcoder/abc117c.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +typedef long long ll; +const int N = 1e5 + 50; +int a[N]; +int main() +{ + int n, m; + ll ans = 0; + scanf("%d%d", &n, &m); + for (int i = 0; i < m; i++) + scanf("%d", a + i); + sort(a, a + m); + for (int i = 1; i < m; i++) + a[i - 1] = a[i] - a[i - 1]; + sort(a, a + m - 1, greater()); + for (int i = n - 1; i < m - 1; i++) + ans += a[i]; + printf("%lld", ans); + return 0; +} \ No newline at end of file diff --git a/java/1.java b/java/1.java new file mode 100644 index 0000000..0f03ff6 --- /dev/null +++ b/java/1.java @@ -0,0 +1,20 @@ +import java.io.PrintStream; +import java.math.BigInteger; +import java.util.Scanner; +import java.util.StringTokenizer; + +class Main { + public static void main(String[] argv) { + String sp = System.getProperty("line.separator"); + PrintStream cout = System.out; + try (Scanner cin = new Scanner(System.in)) { + int T = cin.nextInt(); + for (int t = 1; t <= T; t++) { + BigInteger ba = cin.nextBigInteger(), bb = cin.nextBigInteger(); + cout.printf("Case %d:%s%s + %s = %s%s", t, sp, ba, bb, ba.add(bb), sp); + if (t != T) + cout.println(); + } + } + } +} \ No newline at end of file diff --git a/nw/sock/client.py b/nw/sock/client.py new file mode 100644 index 0000000..0261000 --- /dev/null +++ b/nw/sock/client.py @@ -0,0 +1,11 @@ +from socket import * +from struct import * + +while True: + st = input(">>> ") + s = socket(AF_INET, SOCK_STREAM) + s.connect(("127.0.0.1", 8888)) + s.sendall(pack("!i", len(st.encode()))) + s.sendall(st.encode()) + print(s.recv(len(st)).decode()) + s.close() \ No newline at end of file diff --git a/nw/sock/server.py b/nw/sock/server.py new file mode 100644 index 0000000..aac25c8 --- /dev/null +++ b/nw/sock/server.py @@ -0,0 +1,18 @@ +from socket import * +from struct import * +from threading import * +s = socket(AF_INET, SOCK_STREAM) +s.bind(('', 8888)) +s.listen(100) + + +def proc(cs): + msglen = unpack("!i", cs.recv(4))[0] + msg = cs.recv(msglen) + cs.sendall(msg.decode().upper().encode()) + + +while True: + (cs, addr) = s.accept() + # Thread(None, proc, args=(cs, )).start() + proc(cs) diff --git a/tmp/1.cpp b/tmp/1.cpp new file mode 100644 index 0000000..e17647d --- /dev/null +++ b/tmp/1.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +uint8_t encode[48] = { + 0x96, 0x62, 0x53, 0x43, 0x6D, 0xF2, 0x8F, 0xBC, + 0x16, 0xEE, 0x30, 0x05, 0x78, 0x00, 0x01, 0x52, + 0xEC, 0x08, 0x5F, 0x93, 0xEA, 0xB5, 0xC0, 0x4D, + 0x50, 0xF4, 0x53, 0xD8, 0xAF, 0x90, 0x2B, 0x34, + 0x81, 0x36, 0x2C, 0xAA, 0xBC, 0x0E, 0x25, 0x8B, + 0xE4, 0x8A, 0xC6, 0xA2, 0x81, 0x9F, 0x75, 0x55}; + +int main() +{ + for (int j = 0; j < 6; j++) + { + uint64_t x = *(uint64_t *)&encode[j << 3]; + for (int i = 0; i < 64; i++) + if (x & 1) + x = (x ^ 0xB0004B7679FA26B3uLL) >> 1 | (1ll << 63); + else + x >>= 1; + char *pt = (char *)&x; + for (int i = 0; i < 8; i++) + putchar(pt[i]); + } + return 0; +} diff --git a/tmp/K.cpp b/tmp/K.cpp new file mode 100644 index 0000000..01a0303 --- /dev/null +++ b/tmp/K.cpp @@ -0,0 +1,106 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; + +constexpr double eps = 1e-8; +int sgn(double x) +{ + if (x > eps) + return 1; + if (x < -eps) + return -1; + return 0; +} +template +using enable_if_arithmetic = typename enable_if::value>::type; +template +using enable_if_integral = typename enable_if::value>::type; +template > +struct Point +{ + T x, y; + Point OPX(-, Point, rhs) const { return {x - rhs.x, y - rhs.y}; } + T OPX(*, Point, rhs) const { return x * rhs.x + y * rhs.y; } + T OPX (^, Point, rhs) const { return x * rhs.y - y * rhs.x; } + T len2() const { return x * x + y * y; } + double len() const { return sqrt(len2()); } +}; +template +struct Line +{ + Point s, e; + T len2() const { return (s - e).len2(); } + double len() const { return (s - e).len(); } + bool contains(CRP(Point, p)) const { return sgn((s - p) ^ (e - p)) == 0 && sgn((s - p) * (e - p)) <= 0; } +}; +#define Point Point +#define Line Line +double area(CRP(Point, p1), CRP(Point, p2), CRP(Point, p3)) +{ + return abs((p3 - p1) ^ (p2 - p1)); +} +int main2() +{ + Point p[3], e; + while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &e.x, &e.y)) + { + Line ls[3] = {{p[1], p[2]}, {p[0], p[2]}, {p[0], p[1]}}; + bool flag = true; + for (int i = 0; i < 3 && flag; i++) + if (ls[i].contains(e)) + { + int l = (i + 2) % 3, r = (i + 1) % 3; + int near = (e - p[l]).len2() < (e - p[r]).len2() ? l : r; + int other = l + r - near; + double len = ls[i].len() * ls[near].len() / 2 / (e - p[other]).len(); + double fulllen = ls[near].len(); + Point dif = p[i] - p[other]; + printf("%.12lf %.12lf\n", p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen); + if (sgn(area(p[other], e, {p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen}) * 2 - area(p[0], p[1], p[2]))) + return -1; + flag = false; + } + if (flag) + puts("-1"); + } + return 0; +} +int main() +{ + Point p[3], e; + while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &e.x, &e.y)) + { + Line ls[3] = {{p[1], p[2]}, {p[0], p[2]}, {p[0], p[1]}}; + bool flag = true; + for (int i = 0; i < 3 && flag; i++) + if (ls[i].contains(e)) + { + int l = (i + 2) % 3, r = (i + 1) % 3; + int near = (e - p[l]).len2() < (e - p[r]).len2() ? l : r; + int other = l + r - near; + double len = sqrt(ls[i].len2() * ls[near].len2() / 4 / (e - p[other]).len2()); + double fulllen = ls[near].len(); + Point dif = p[i] - p[other]; + printf("%.12lf %.12lf\n", p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen); + if (sgn(area(p[other], e, {p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen}) * 2 - area(p[0], p[1], p[2]))) + return -1; + flag = false; + } + if (flag) + puts("-1"); + } + return 0; +} \ No newline at end of file diff --git a/tmp/test1.ipynb b/tmp/test1.ipynb new file mode 100644 index 0000000..c9e99de --- /dev/null +++ b/tmp/test1.ipynb @@ -0,0 +1,49 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + } + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "array([[0., 0., 0.],\n [0., 0., 0.],\n [0., 0., 0.],\n [0., 0., 0.],\n [0., 0., 0.]])" + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.zeros((5,3))" + ] + } + ] +} \ No newline at end of file diff --git a/tmpl.cpp b/tmpl.cpp new file mode 100644 index 0000000..57ff51b --- /dev/null +++ b/tmpl.cpp @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef long long ll, i64; +int main() +{ + + return 0; +} \ No newline at end of file diff --git a/tmpl.h b/tmpl.h deleted file mode 100644 index e33a75e..0000000 --- a/tmpl.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#ifndef __TMPL_H_ -#define __TMPL_H_ -#include -template -class range -{ -private: - class range_iterator : std::iterator - { - private: - T val, step; - public: - range_iterator(T x, T sp) : val(x), step(sp) {} - bool operator==(const range_iterator &rhs) const noexcept - { - if (step > 0) return val - step < rhs.val && val >= rhs.val; - if (step < 0) return val - step > rhs.val && val <= rhs.val; - return val == rhs.val; - } - bool operator!=(const range_iterator &rhs) const noexcept { return !(*this == rhs); } - const auto &operator++() { return val += step, *this; } - T &operator*() { return val; } - } st, ed; - -public: - range(T ed) : range(0, ed, 1) {} - range(T st, T ed, T sp = 1) : st(st, sp), ed(ed, sp) {} - const range_iterator &begin() { return st; } - const range_iterator &end() { return ed; } -}; -#endif \ No newline at end of file