From cacc165173d67fa110766a555afe3020967d220c Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 14 Oct 2019 20:59:08 +0700 Subject: Practice some C++ --- codechef/marm.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ codechef/msng.py | 25 +++++++++++++++++++++++ codechef/msv.cc | 39 ++++++++++++++++++++++++++++++++++++ codechef/s10e.cc | 35 ++++++++++++++++++++++++++++++++ codechef/saktan.cc | 32 ++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 codechef/marm.cc create mode 100755 codechef/msng.py create mode 100644 codechef/msv.cc create mode 100644 codechef/s10e.cc create mode 100644 codechef/saktan.cc (limited to 'codechef') diff --git a/codechef/marm.cc b/codechef/marm.cc new file mode 100644 index 0000000..3866330 --- /dev/null +++ b/codechef/marm.cc @@ -0,0 +1,58 @@ +#include +#include + +using namespace std; + +int +main() +{ + int t, n; + long k; + + cin >> t; + while (t--) + { + cin >> n >> k; + long d = k / n, m = k % n; + vector a (n); + for (int i = 0; i < n; ++i) + cin >> a[i]; + + for (int i = 0; i < n / 2; ++i) + { + switch ((d + (m > i)) % 3) + { + case 1: + cout << (a[i] ^ a[n - i - 1]); + break; + case 2: + cout << a[n - i - 1]; + break; + default: + cout << a[i]; + } + cout << ' '; + } + + if (n % 2) + cout << ((d + (m > n >> 1)) ? 0 : a[n >> 1]) << ' '; + + for (int i = n - (n >> 1); i < n; ++i) + { + switch ((d + (m > i)) % 3) + { + case 1: + cout << a[n - i - 1]; + break; + case 2: + cout << (a[i] ^ a[n - i - 1]); + break; + default: + cout << a[i]; + } + cout << ((i + 1 == n) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/codechef/msng.py b/codechef/msng.py new file mode 100755 index 0000000..bf8b262 --- /dev/null +++ b/codechef/msng.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +from collections import Counter + +for t in range(int(input())): + n, x = int(input()), [] + for i in range(n): + b, y = input().split() + if b == '-1': + guesses = set() + for b in range(2, 37): + try: + guess = int(y, b) + except ValueError: + pass + else: + if guess > 10 ** 12: break + guesses.add(guess) + x.extend(guesses) + else: + guess = int(y, int(b)) + if guess <= 10 ** 12: x.append(guess) + try: + print(min(k for k, v in Counter(x).items() if v == n)) + except ValueError: + print(-1) diff --git a/codechef/msv.cc b/codechef/msv.cc new file mode 100644 index 0000000..6206cff --- /dev/null +++ b/codechef/msv.cc @@ -0,0 +1,39 @@ +#include +#include +#include + +using namespace std; + +int +main() +{ + int t, n, i; + long a; + + cin >> t; + while (t--) + { + int star = 0; + unordered_map m; + + cin >> n; + while (n--) + { + cin >> a; + star = max (m[a], star); + + for (i = 1; i * i < a; ++i) + if (a % i == 0) + { + m[i]++; + m[a / i]++; + } + if (i * i == a) + m[i]++; + } + + cout << star << endl; + } + + return 0; +} diff --git a/codechef/s10e.cc b/codechef/s10e.cc new file mode 100644 index 0000000..5e5c0b7 --- /dev/null +++ b/codechef/s10e.cc @@ -0,0 +1,35 @@ +#include +#include +#include + +using namespace std; + +int +main() +{ + int t; + int tmp; + deque p; + + cin >> t; + while (t--) + { + int n; + int r = 0; + + cin >> n; + p.clear(); + while (n--) + { + cin >> tmp; + auto it = min_element (p.begin(), p.end()); + r += it == p.end() || *it > tmp; + p.push_back (tmp); + if (p.size() > 5) + p.pop_front(); + } + cout << r << endl; + } + + return 0; +} diff --git a/codechef/saktan.cc b/codechef/saktan.cc new file mode 100644 index 0000000..96ef43a --- /dev/null +++ b/codechef/saktan.cc @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +int +main() +{ + int t; + long n, m, q, x, y; + + cin >> t; + while (t--) + { + cin >> n >> m >> q; + vector u (n), v (m); + + while (q--) + { + cin >> x >> y; + u[x - 1] ^= 1; + v[y - 1] ^= 1; + } + + x = accumulate (u.begin(), u.end(), 0); + y = accumulate (v.begin(), v.end(), 0); + cout << x * (m - y) + (n - x) * y << endl; + } + + return 0; +} -- cgit 1.4.1