From 8ba6ad7ebc29e77d3fcbcbca6c0628e2eda3349b Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 8 Aug 2021 16:35:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=B1=8A=E2=80=9C=E5=9B=BE?= =?UTF-8?q?=E7=81=B5=E6=9D=AF=E2=80=9D=E8=B6=A3=E5=91=B3=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=82=80=E8=AF=B7=E8=B5=9B=20(=E4=B8=AD=E7=BA=A7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XJOI/contest/21med/A/A.cpp | 26 +++++++++++++++++++ XJOI/contest/21med/B/B.cpp | 52 ++++++++++++++++++++++++++++++++++++++ XJOI/contest/21med/C/C.cpp | 33 ++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 XJOI/contest/21med/A/A.cpp create mode 100644 XJOI/contest/21med/B/B.cpp create mode 100644 XJOI/contest/21med/C/C.cpp diff --git a/XJOI/contest/21med/A/A.cpp b/XJOI/contest/21med/A/A.cpp new file mode 100644 index 00000000..66492909 --- /dev/null +++ b/XJOI/contest/21med/A/A.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int n, p; +string s; +stack> st; + +int main() { + cin >> n >> p >> s; + s = ' ' + s; + for (int i = 1; i < s.size(); i++) { + if (s[i] == '{') { + st.push(make_pair(s[i], i)); + } else if (st.top().second == p) { + cout << i << endl; + exit(0); + } else if (i == p) { + cout << st.top().second << endl; + exit(0); + } else { + st.pop(); + } + } + return 0; +} diff --git a/XJOI/contest/21med/B/B.cpp b/XJOI/contest/21med/B/B.cpp new file mode 100644 index 00000000..6155eeae --- /dev/null +++ b/XJOI/contest/21med/B/B.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int t, a, cnt, prime[100005]; +bool flag, is_prime[1000005]; + +int eratosthenes(int n) { + int p = 0; + for (int i = 0; i <= n; i++) is_prime[i] = 1; + is_prime[0] = is_prime[1] = 0; + for (int i = 2; i <= n; i++) { + if (is_prime[i]) { + prime[p++] = i; + if (1ll * i * i <= n) { + for (int j = i * i; j <= n; j += i) { + is_prime[j] = 0; + } + } + } + } + return p; +} + +long long binpow(long long a, long long b, long long m) { + a %= m; + long long res = 1; + while (b > 0) { + if (b & 1) res = res * a % m; + a = a * a % m; + b >>= 1; + } + return res; +} + +int main() { + cin >> t; + cnt = eratosthenes(1000000); + while (t--) { + flag = false; + cin >> a; + for (int i = 0; i < cnt; i++) { + if (binpow(a, prime[i], 10) % 10 == binpow(prime[i], a, 10) % 10) { + cout << prime[i] << endl; + flag = true; + break; + } + } + if (!flag) cout << -1 << endl; + } + return 0; +} diff --git a/XJOI/contest/21med/C/C.cpp b/XJOI/contest/21med/C/C.cpp new file mode 100644 index 00000000..2a8b2846 --- /dev/null +++ b/XJOI/contest/21med/C/C.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + +int n; +long long ans, cnt, x; +pair q[300005]; + +bool cmp(pair a, pair b) { + return (a.first - b.first) * (a.second + b.second) > (a.first + b.first) * (a.second - b.second); +} + +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> q[i].first >> q[i].second; + } + sort(q, q + n, cmp); + for (int i = 0; i < n; i++) { + cnt += abs(2 * q[i].second * x + q[i].second * q[i].first); + x += q[i].first; + } + ans = max(ans, cnt); + x = 0; + cnt = 0; + for (int i = n - 1; i >= 0; i--) { + cnt += abs(2 * q[i].second * x + q[i].second * q[i].first); + x += q[i].first; + } + ans = max(ans, cnt); + cout << ans << endl; + return 0; +}